当前位置: 编程技术>php
本页文章导读:
▪数字转英文
<?php //___{xf_num2en}________________________________________ //*** 說明: 數值轉英文表示法 //=== 回傳: <string> //--- NN)數值 FF)小數位 //===========================================================.........
▪產生圖片隨機字串
<?php $base = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; $words = 5; $rand_top = strlen($base) - 1; $string = ''; header("Content-type: image/png"); $im = imagecreate($words*16, $words*.........
▪計算你開發的 PHP 程式大小
代码如下:<?php /** * 計算該目錄下的程式規模,包含檔案數,行數,字數 * * @version 1.0 * @since 1.0 * @access public * @author Ryan <ryan@shinersoft.com> * .........
[1]数字转英文
来源: 互联网 发布时间: 2013-11-30
<?php //___{xf_num2en}________________________________________
//*** 說明: 數值轉英文表示法
//=== 回傳: <string>
//--- NN)數值 FF)小數位
//============================================================
function xf_num2en($NN, $FF=0) {
//===[前置]========================================
if (!is_numeric($NN)) return '';
($FF>2) and $FF=2;
$xn=''; $xf='';
global $enws;
$enws=array(
0=>"zero",1=>"one",2=>"two",3=>"three",4=>"four",
5=>"five",6=>"six",7=>"seven",8=>"eight",9=>"nine",
10=>"ten",11=>"eleven",12=>"twelve",
13=>"thirteen",14=>"fourteen", 15=>"fifteen",
16=>"sixteen",17=>"seventeen",18=>"eighteen",19=>"nineteen",
20=>"twenty",30=>"thirty",40=>"forty",50=>"fifty",
60=>"sixty",70=>"seventy",80=>"eighty",90=>"ninety");
//===[整數]========================================
$nk=floor($NN);
$cnt=0;
while ($nk) {
$n=$nk % 1000;
if ($n) {
$x=xf_enNum4($n);
if ($cnt==1) $xn=$x. 'thousand '. $xn;
elseif ($cnt==2) $xn=$x. 'million '. $xn;
elseif ($cnt==3) $xn=$x. 'billion '. $xn;
elseif ($cnt==4) $xn=$x. 'trillion '. $xn;
else $xn=$x;
}
$cnt+=1;
$nk=floor($nk/1000);
} //--while
//===[小數]========================================
if ($FF>0) {
$n=floor($NN*100) % 100;
($n) and $xf=xf_enNum4($n). 'cent';
}
return $xn.$xf;
} //--xf_num2en
function xf_enNum4($NN) {
global $enws;
$ans='';
$n=floor($NN/100);
($n) and $ans=$enws[$n]. ' hundred ';
$n=$NN % 100;
if ($n) {
if ($n<20) $ans.=$enws[$n]. ' ';
else {
$m=floor($n/10) * 10;
$ans.=$enws[$m]. ' ';
$n=$n % 10;
($n) and $ans.=$enws[$n]. ' ';
}
}
return $ans;
} //--xf_enNum4 ?>
//*** 說明: 數值轉英文表示法
//=== 回傳: <string>
//--- NN)數值 FF)小數位
//============================================================
function xf_num2en($NN, $FF=0) {
//===[前置]========================================
if (!is_numeric($NN)) return '';
($FF>2) and $FF=2;
$xn=''; $xf='';
global $enws;
$enws=array(
0=>"zero",1=>"one",2=>"two",3=>"three",4=>"four",
5=>"five",6=>"six",7=>"seven",8=>"eight",9=>"nine",
10=>"ten",11=>"eleven",12=>"twelve",
13=>"thirteen",14=>"fourteen", 15=>"fifteen",
16=>"sixteen",17=>"seventeen",18=>"eighteen",19=>"nineteen",
20=>"twenty",30=>"thirty",40=>"forty",50=>"fifty",
60=>"sixty",70=>"seventy",80=>"eighty",90=>"ninety");
//===[整數]========================================
$nk=floor($NN);
$cnt=0;
while ($nk) {
$n=$nk % 1000;
if ($n) {
$x=xf_enNum4($n);
if ($cnt==1) $xn=$x. 'thousand '. $xn;
elseif ($cnt==2) $xn=$x. 'million '. $xn;
elseif ($cnt==3) $xn=$x. 'billion '. $xn;
elseif ($cnt==4) $xn=$x. 'trillion '. $xn;
else $xn=$x;
}
$cnt+=1;
$nk=floor($nk/1000);
} //--while
//===[小數]========================================
if ($FF>0) {
$n=floor($NN*100) % 100;
($n) and $xf=xf_enNum4($n). 'cent';
}
return $xn.$xf;
} //--xf_num2en
function xf_enNum4($NN) {
global $enws;
$ans='';
$n=floor($NN/100);
($n) and $ans=$enws[$n]. ' hundred ';
$n=$NN % 100;
if ($n) {
if ($n<20) $ans.=$enws[$n]. ' ';
else {
$m=floor($n/10) * 10;
$ans.=$enws[$m]. ' ';
$n=$n % 10;
($n) and $ans.=$enws[$n]. ' ';
}
}
return $ans;
} //--xf_enNum4 ?>
[2]產生圖片隨機字串
来源: 互联网 发布时间: 2013-11-30
<?php
$base = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$words = 5;
$rand_top = strlen($base) - 1;
$string = '';
header("Content-type: image/png");
$im = imagecreate($words*16, $words*5);
$black = imagecolorallocate($im, 90, 60, 120);
$white = imagecolorallocate($im, 255, 255, 255);
for($i=0;$i<$words;$i++){
$idx = mt_rand(0, $rand_top);
imagestring($im, 3, $i*15+2, mt_rand(0, $words*2), $base[$idx], $white);
}
imagepng($im);
imagedestroy($im);
?>
$base = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$words = 5;
$rand_top = strlen($base) - 1;
$string = '';
header("Content-type: image/png");
$im = imagecreate($words*16, $words*5);
$black = imagecolorallocate($im, 90, 60, 120);
$white = imagecolorallocate($im, 255, 255, 255);
for($i=0;$i<$words;$i++){
$idx = mt_rand(0, $rand_top);
imagestring($im, 3, $i*15+2, mt_rand(0, $words*2), $base[$idx], $white);
}
imagepng($im);
imagedestroy($im);
?>
[3]計算你開發的 PHP 程式大小
来源: 互联网 发布时间: 2013-11-30
代码如下:
<?php
/**
* 計算該目錄下的程式規模,包含檔案數,行數,字數
*
* @version 1.0
* @since 1.0
* @access public
* @author Ryan <ryan@shinersoft.com>
* @copyright Copyright (c) 2002-2004 by Shiner Technologies Co., Ltd.
* @package AAPortal
*/
// 請修改這個目錄的位置
$dir = "aaportal";
// 以下不用更動
$counts = array("directory" => 0, "file" => 0, "line" => 0, "size" => 0);
check($dir);
echo "Total:\n";
echo "Directry : ".$counts["directory"]."\n";
echo "File : ".$counts["file"]."\n";
echo "Line : ".$counts["line"]."\n";
echo "Size : ".$counts["size"]."\n";
function check($dir)
{
global $counts;
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if ($file == ".") continue;
if ($file == "..") continue;
if ($file == "CVS") continue;
$path = $dir."/".$file;
if (is_dir($path)) {
$counts["directory"]++;
//echo "dir ".$counts["directory"]." $path\n";
check($path);
} else {
$ext = array_pop(explode('.', basename($path)));
if ($ext=="php" || $ext=="inc") {
$counts["file"]++;
//echo "file ".$counts["file"]." $path\n";
$lines = file($path);
$counts["line"] += count($lines);
$counts["size"] += filesize($path);
}
}
}
closedir($dh);
}
} ?>
/**
* 計算該目錄下的程式規模,包含檔案數,行數,字數
*
* @version 1.0
* @since 1.0
* @access public
* @author Ryan <ryan@shinersoft.com>
* @copyright Copyright (c) 2002-2004 by Shiner Technologies Co., Ltd.
* @package AAPortal
*/
// 請修改這個目錄的位置
$dir = "aaportal";
// 以下不用更動
$counts = array("directory" => 0, "file" => 0, "line" => 0, "size" => 0);
check($dir);
echo "Total:\n";
echo "Directry : ".$counts["directory"]."\n";
echo "File : ".$counts["file"]."\n";
echo "Line : ".$counts["line"]."\n";
echo "Size : ".$counts["size"]."\n";
function check($dir)
{
global $counts;
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if ($file == ".") continue;
if ($file == "..") continue;
if ($file == "CVS") continue;
$path = $dir."/".$file;
if (is_dir($path)) {
$counts["directory"]++;
//echo "dir ".$counts["directory"]." $path\n";
check($path);
} else {
$ext = array_pop(explode('.', basename($path)));
if ($ext=="php" || $ext=="inc") {
$counts["file"]++;
//echo "file ".$counts["file"]." $path\n";
$lines = file($path);
$counts["line"] += count($lines);
$counts["size"] += filesize($path);
}
}
}
closedir($dh);
}
} ?>
最新技术文章: