Time of Update: 2017-01-13
在php當中變數的作用範圍php手冊上是這樣描述的在使用者自訂函數中,一個局部函數範圍將被引入。任何用於函數內部的變數按預設情況將被限制在局部函數範圍內。例如: 代碼如下複製代碼 <?php$a = 1; /* global scope */function Test(){ echo $a; /* reference to local scope variable */}Test();?> 這個指令碼不會有任何輸出,因為 echo
Time of Update: 2017-01-13
php執行個體gzip傳輸頁面 代碼如下複製代碼 可以用於靜態資源與html頁面,修改一下也適合於其他語言//緩衝到期時間(Cache-Control, http1.1協義), 推薦使用$secs = 0; //秒header("Cache-Control: s-maxage=$secs, max-age=$secs, must-revalidate, proxy-revalidate");// 緩衝到期時間為24小時(Expires)$offset =
Time of Update: 2017-01-13
例 代碼如下複製代碼 <?php$a=12;function fn(){ global $a;//使用外層$a變數,不使用這個方法$a為局部變數 $a+=12;}echo '$a='.$a//輸出結果?>輸出的結果:$a=24 總結:在函數體內定義的global變數,函數體外可以使用,在函數體外定義的global變數不能在函數體內使用, 代碼如下複製代碼 $glpbal $a; $a=
Time of Update: 2017-01-13
下面是程式碼: 代碼如下複製代碼 function mkdirs($dir){if(!is_dir($dir)){if(!mkdirs(dirname($dir))){return false;}if(!mkdir($dir,0777)){return false;}}return true;}mkdirs('div/css/layout'); 同樣的思路,php用rmdir和unlink遞迴刪除多級目錄的代碼: 代碼如下複製代碼 function
Time of Update: 2017-01-13
-設計一個程式流程 1.功能需要 2.頁面設計 3.資料庫設計 4.代碼設計 5.調試發布
Time of Update: 2017-01-13
然而今天我卻發現這個__autoload魔術方法或者你願意稱他為魔術函數,太專一了。當他載入需要包含的類檔案時,甚至不管類檔案中定義類之外的其它聲明。開始回放這個機制。首先我們在建立一個Test.class.php檔案,鍵入如下內容 代碼如下複製代碼 $publicPara='中共十七大啥時候召開的?';class Test{ public function __construct(){ global $publicPara;
Time of Update: 2017-01-13
代碼如下複製代碼 /** * 獲得使用者的真實IP地址 * * @return string */function real_ip(){ static $realip = NULL; if ($realip !== NULL){ return $realip;&
Time of Update: 2017-01-13
用的是表頭方式下載 代碼如下複製代碼 Header( "Content-type: application/octet-stream "); Header( "Accept-Ranges: bytes "); Header( "Accept-Length: ".filesize($file_dir
Time of Update: 2017-01-13
代碼如下複製代碼 <?php function foreachDir($path){ $handle=opendir($path); if($handle){ while (false !== ($file = readdir($handle))) { if($file!="." && $file!='..'){ if(is_dir($path.$file)){ echo
Time of Update: 2017-01-13
代碼如下複製代碼 function smssubstr($string, $length) { if(strlen($string) <= $length) { return $string; } $strcut = ''; for($i = 0; $i < $length; $i++) { $strcut .= ord($string[$i]) > 127 ?
Time of Update: 2017-01-13
代碼如下複製代碼 <?php $s = rand(100,200); $pi=pi(); $r=sqrt($s/$pi); $qz1=round($r); //四捨五入取整 $qz2=ceil($r); //進一法取整 $qz3=floor($r); //捨去法取整
Time of Update: 2017-01-13
代碼如下複製代碼 <html><head><title>Login</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head> <body><form name="form1" method="post"
Time of Update: 2017-01-13
使用php讓瀏覽器重新整理需要解決幾個問題如果用戶端瀏覽器關閉,程式可能就被迫終止,解決辦法:ignore_user_abort即使關閉頁面依然正常執行 如果程式一直執行很有可能會消耗大量的資源,解決辦法使用sleep使用程式休眠一會,然後在執行 PHP定時執行的代碼: 代碼如下複製代碼 <?phpignore_user_abort();//關掉瀏覽器,PHP指令碼也可以繼續執行.set_time_limit(3000);//
Time of Update: 2017-01-13
日期比較如 2011-11-11 2011-12-12 代碼如下複製代碼 function compare_date( $DATE1, $DATE2 ) { $STR = strtok( $DATE1, "-" ); $YEAR1 = $STR;
Time of Update: 2017-01-13
代碼如下複製代碼 // 函數名:CheckEmailAddr($C_mailaddr)// 作 用:判斷是否為有效郵件地址// 參 數:$C_mailaddr(待檢測的郵件地址)// 傳回值:布爾值// 備 註:無function CheckEmailAddr($C_mailaddr){if
Time of Update: 2017-01-13
調用<?php/** * 新浪部落格編輯器PHP版封裝類調用方法 * */header(\'Content-Type:text/html;Charset=utf-8;\');include_once(\'sinaEditor.class.php\');extract($_POST);extract($_GET);unset($_POST,$_GET);$act==\'subok\' && die("提交的內容是:<br>
Time of Update: 2017-01-13
用本站上其他網友提供的EXCEL類匯入資料後,在MYSQL中顯示的都是श...等之類的代碼,無法顯示中文。我在使用過程中也是如此,為此我在網上查詢很久,最終對兩位網友提供的類進行了綜合,解決了此類問題,請大家下載使用! 我們都是探討,如果侵犯了原作者著作權,請諒解!!!! 如果不同意,我就立即刪除!對此類的運用方法如下:<?phprequire
Time of Update: 2017-01-13
<?php session_start(); //產生驗證碼圖片 Header("Content-type: image/PNG"); $im = imagecreate(44,18); // 畫一張指定寬高的圖片 $back = ImageColorAllocate($im, 245,245,245); // 定義背景顏色 imagefill($im,0,0,$back); //把背景顏色填充到剛剛畫出來的圖片中 $vcodes =
Time of Update: 2017-01-13
//方法一 用while來些fgets一行行讀$file_name="1.txt"; 代碼如下複製代碼 $fp=fopen($file_name,'r'); while(!feof($fp)) { $buffer=fgets($fp,4096); echo $buffer."<br>"; } fclose($fp); // 方法二
Time of Update: 2017-01-13
If we want to add on to a file we need to open it up in append mode. The code below does just that.*/ 代碼如下複製代碼 $text = "test.txt";if( file_exists( $text ) && is_file( $text ) ){ $fh = fopen($myFile, 'a'); if(