PHP動態網頁開發中常用的一些函數_PHP教程

來源:互聯網
上載者:User

在php網頁的開頭加入以下

以下為引用的內容:
$time_start = getmicrotime();
function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
?>

然後到最後加入以下代碼

以下為引用的內容:
$time_end = getmicrotime();
printf ("[頁面執行時間: %.2f毫秒]",($time_end - $time_start)*1000);
?>

$file = fopen($filename, r) or die("抱歉,無法開啟: $filename");

or在這裡是這樣理解的,因為在php中並不區分資料類型,所以$file既可以是int也可以bool,所以這樣的語句不會報錯。但其處理過程可能有些朋友不大明白。

其實在大多數的語言中, bool or bool這樣的語句中,如果前一個值為真後一個值就不會再判斷了。這裡也是的,所以如果fopen函數執行正確的話,會返回一個大於0的int值(這其實就是“真”),後面的語句就不會執行了。如果fopen函數執行失敗,就會返回false,那麼就會判斷後面的運算式是否為真了。

結果執行了die()之後,不管返回什麼,程式都已經停止執行了,並且顯示指定的出錯資訊,也就達到了調試的目的。

php複選框的問題

以下為引用的內容:

d.php

以下為引用的內容:
$fd=$_post[checkbox];
for ($i = 0; $i < (sizeof($fd)); $i++) {
$newhpt=$newhpt.$fd[$i].",";
}
echo $newhpt."
";
?>

php代碼中函數前面的@是什麼意思?

@的作用是忽略調用該函數時產生的錯誤資訊。

php中日期相加的問題

以下為引用的內容:
$fd=$_post[checkbox];
for ($i = 0; $i < (sizeof($fd)); $i++) {
$newhpt=$newhpt.$fd[$i].",";
}
echo $newhpt."
";
?>

關於php浮水印的問題

以下為引用的內容:
//讀取目標檔案
$im = imagecreatefromjpeg("1[2].jpg");
//設定混合模式
imagealphablending($im, true);
//讀取浮水印
$im2 = imagecreatefrompng("watermark.png");
//下面是我寫的字,可以不看
//$color = imagecolorallocate($im2, 0, 0, 0);
//imagestring($im2, 12, 1, 1, "i love u jingjing", $color);
//字結束
//拷貝浮水印到目標檔案
imagecopy($im, $im2, 5, 5, 0, 0, 220, 34);
//輸出,可以輸出到檔案裡
imagejpeg($im);
imagedestroy($im);
imagedestroy($im1);
?>
$im = imagecreatefromjpeg("1[2].jpg");
//$im = imagecreatefromgif("eee.gif");
//$im = imagecreatefrompng("1[2].png");
$black = imagecolorallocate ($im, 0, 140, 76);
$red = imagecolorallocate ($im, 255, 0, 0);
$string=chr(0xe5).chr(0xae).chr(0x89).chr(0xe5).chr(0xba).chr(0x86).chr(0xe6).chr(0x88).chr(0xbf).chr(0xe4).chr(0xba).chr(0xa7).chr(0xe7).chr(0xbd).chr(0x91);
//imagestring ($im,12,10,10,$string,$red);
imagettftext($im,20,0,4,30,$red,"fzdhtjw.ttf",$string);
imagepng ($im);
imagedestroy ($im);
?>
//這個函數是把漢字轉換成utf-8後,就可以在gd中使用了!
function gb2utf8($gb)
{
if(!trim($gb))
return $gb;
$filename="gb2312.txt";
$tmp=file($filename);
$codetable=array();
while(list($key,$value)=each($tmp))
$codetable[hexdec(substr($value,0,6))]=substr($value,7,6);
$utf8="";
while($gb)
{
if (ord(substr($gb,0,1))>127)
{
$this=substr($gb,0,2);
$gb=substr($gb,2,strlen($gb));
$utf8.=u2utf8(hexdec($codetable[hexdec(bin2hex($this))-0x8080]));
}
else
{
$gb=substr($gb,1,strlen($gb));
$utf8.=u2utf8(substr($gb,0,1));
}
}
$ret="";
for($i=0;$i$ret.=chr(substr($utf8,$i,3));
return $ret;
}
function u2utf8($c)
{
for($i=0;$i$str="";
if ($c < 0x80) {
$str.=$c;
}
else if ($c < 0x800) {
$str.=(0xc0 | $c>>6);
$str.=(0x80 | $c & 0x3f);
}
else if ($c < 0x10000) {
$str.=(0xe0 | $c>>12);
$str.=(0x80 | $c>>6 & 0x3f);
$str.=(0x80 | $c & 0x3f);
}
else if ($c < 0x200000) {
$str.=(0xf0 | $c>>18);
$str.=(0x80 | $c>>12 & 0x3f);
$str.=(0x80 | $c>>6 & 0x3f);
$str.=(0x80 | $c & 0x3f);
}
return $str;
}
header("content-type: image/gif");
$im = imagecreate(400,300);
$bkg = imagecolorallocate($im, 0,0,0);
$clr = imagecolorallocate($im, 255,255,255);
$fnt = "wb.ttf";
//include("gb2utf8.php");
$str = gb2utf8("中國");
imagettftext($im, 20, 0, 10, 20, $clr, $fnt, $str);
imagegif($im);
imagedestroy($im);
?>

以下為引用的內容:

//對javascript和select組件的結合運用
//在寫程式的過程,我想實現在select對象選中選項後,
//不需要提交按鈕,而直接觸發動作,且在動作發生後
//的頁面中要保持所選擇的選項。經過形容,終於通過
//使用javascript及select對象的onchange屬性及
//value值而實現了這種功能。
//代碼如下(檔案名稱為"test.php"):

switch ($mon){
case : echo 請選擇您的星座:;break;
case 1:echo 您的星座是水瓶座;break;
&

http://www.bkjia.com/PHPjc/531677.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/531677.htmlTechArticle在php網頁的開頭加入以下 以下為引用的內容: ? $time_start = getmicrotime(); function getmicrotime() { list($usec, $sec) = explode(" ",microtime()); return ((float...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.