Time of Update: 2016-07-25
//a$arr=array('a'=>'abc','b'=>123,'c'=>true);//b//$arr=range('a','d');//1for($i=0;$iecho $arr[$i].', ';echo '';//2foreach($arr as $key)echo "$key, ";echo '';//3foreach($arr as $key=>$val)echo "$key-$val, ";echo
Time of Update: 2016-07-25
$a = array( 'a',);$b = array( 'u',);$c = $a + $b;var_dump($c);複製代碼輸出: $a = array( 66=>'a',);$b = array( 60=>'u', 66=>'c');$c = $a + $b;var_dump($c);複製代碼輸出: $a = array( 1=>'a', 2=>'b', 'c'=>'c', 'd'=>'d',);$b = array( 1=>
Time of Update: 2016-07-25
/*** 檔案下載* 多種檔案格式,包括pdf、zip、gif、jpg、mpeg、word等。* edit bbs.it-home.org*/function dl_file($file){ //First, see if the file exists if (!is_file($file)) { die("404 File not found!"); } //Gather relevent info about file $len = filesize($file);
Time of Update: 2016-07-25
/*** 計算兩個日期間隔的年、月、周、日數* edit bbs.it-home.org*/function format($a,$b){//檢查兩個日期大小,預設前小後大,如果前大後小則交換位置以保證前小後大if(strtotime($a)>strtotime($b)) list($a,$b)=array($b,$a);$start = strtotime($a);$stop = strtotime($b);$extend =
Time of Update: 2016-07-25
/*** php自訂gzdecode解壓縮gzip檔案* edit bbs.it-home.org*/if (!function_exists('gzdecode')) { function gzdecode ($data) { $flags = ord(substr($data, 3, 1)); $headerlen = 10; $extralen = 0; $filenamelen = 0; if ($flags & 4) { $extralen = unpack('v' ,substr($
Time of Update: 2016-07-25
/*** 等比例縮小的縮圖* edit bbs.it-home.org*/ function thumbs($FileName,$SaveTo,$SetW,$SetH){ $IMGInfo= getimagesize($FileName); if(!$IMGInfo) return false; if($IMGInfo[mime]== "image/pjpeg" || $IMGInfo[mime]=="image/jpeg"){
Time of Update: 2016-07-25
/** * php 驗證碼 可自訂大小 * edit bbs.it-home.org*/function vCode($num=4,$size=20, $width=0,$height=0){!$width && $width = $num*$size*4/5+5;!$height && $height = $size + 10;// 去掉了 0 1 O l 等$str =
Time of Update: 2016-07-25
$_COOKIE["counter"]?($c=$_COOKIE["counter"]+1):($c=1);setCookie("counter",$c,time()+60);echo "歡迎您第"."".$c."次訪問cookie";//by bbs.it-home.org?>複製代碼下面是有關這個例子的代碼說明,供大家參考。以上代碼中,首先,瀏覽器請求一個資源(這個php頁面),發送下面的HTTP包頭內容到伺服器: GET http://localhost/index.php HTTP/1.
Time of Update: 2016-07-25
//即使Client斷開(如關掉瀏覽器),PHP指令碼也可以繼續執行.ignore_user_abort();// 執行時間為無限制,php預設的執行時間是30秒,通過set_time_limit(0)可以讓程式無限制的執行下去set_time_limit(0);// 每隔5分鐘運行$interval=60*5;do{$url = “http://bbs.it-home.org”;$ch = curl_init();curl_setopt($ch, CURLOPT_URL,
Time of Update: 2016-07-25
void ob_start(void);?>複製代碼告訴PHP處理器把所有的輸出重新導向到一個內部的緩衝(buffer)中。在調用ob_start之前,沒有輸出會被送到瀏覽器去。 string ob_get_contents(void);?>複製代碼該函數將“輸出緩衝”(output buffer)以字串的形式返回。你可以調用該函數把積累下來的輸出送到瀏覽器中。(僅在把buffering功能關閉之後!!) int ob_get_length(void);?>複製代碼返回緩衝中的字串的長度。
Time of Update: 2016-07-25
//方法1echo date("Y-m-d h:i:s"); //方法2date_default_timezone_set('Asia/Chongqing'); //系統時間差8小時問題$now = getdate(time());$cur_wday=$now['wday'];$date = date("Y-m-d H:i:s $cweekday[$cur_wday]");echo $date;//by bbs.it-home.org?> 複製代碼date函數中字母代表的含義:a -
Time of Update: 2016-07-25
zlib.output_compression = Off;zlib.output_compression_level = -1 複製代碼修改為: zlib.output_compression = Onzlib.output_compression_level = 6複製代碼其中,zlib.output_compression_level = 6 的數字6是壓縮比例二、開啟apache 設定檔httpd.conf,配置裝載deflate_module,找到#LoadModule
Time of Update: 2016-07-25
CREATE TABLE ccol(id integer not null auto_increment, #記錄的IDip char(15) not null, #訪問者的IP地址dtstamp datetime not null, #最後訪問時間uri char(255), #訪問者請求的URIprimary key (id));複製代碼然後,編寫統計用的php代碼 /*檔案:ccol.php目的:統計同時線上瀏覽的人數edit: bbs.it-home.org*/$duration=180
Time of Update: 2016-07-25
本文介紹下,如何通過配置php.ini檔案來實現屏蔽php錯誤的方法,供大家學習參考。在php的設定檔 php.ini中配置相關內容,實現屏蔽php中相關錯誤。如下所示:; Error handling and logging ;; 出錯控制和登記 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 錯誤報表是按位的。或者將數字加起來得到想要的錯誤報表等級。; E_ALL - 所有的錯誤和警告; E_ERROR - 致命性運行時錯; E_WARNING - 運行時警告(非致命性錯)
Time of Update: 2016-07-25
output_buffering = Offoutput_handler =zlib.output_compression = On 複製代碼即可實現為全站的php檔案啟用gzip加速。對於html檔案,可以通過配置.htaccess檔案,由php來處理html請求(會加重伺服器負擔,建議在nginx或apache上做gzip處理): AddHandler x-httpd-php .html
Time of Update: 2016-07-25
unserialize(iconv('gbk','utf-8',serialize($array))); 複製代碼結果是空白的。藉助var_export函數,最終函數如下: function array_iconv($in_charset,$out_charset,$arr){ return eval('return '.iconv($in_charset,$out_charset,var_export($arr,true).';'));}
Time of Update: 2016-07-25
/*** php表單字元轉義* 防止sql注入* edit bbs.it-home.org*/function quotes($content){//如果magic_quotes_gpc=Off,那麼就開始處理if (!get_magic_quotes_gpc()) {//判斷$content是否為數組if (is_array($content)) {//如果$content是數組,那麼就處理它的每一個單無foreach ($content as $key=>$value) {$content[
Time of Update: 2016-07-25
$i = 3;ob_start();while ($i--) { echo $i, ""; ob_flush(); flush(); sleep(1);}ob_end_clean();?> 複製代碼問題:這段代碼不能每隔一秒輸出呢?原因分析:apache運行原理:當訪問一個地址(發送請求)後,在apache伺服器中啟動PHP,php執行是頁面級的,如果有可執行檔代碼:它全部執行完後再丟給apache,apache再丟給browser顯示結果。解決方案:如果是cli
Time of Update: 2016-07-25
//判斷 0 和 '' 以及 empty null false的關係 start//if('safdasefasefasf'==0){ echo "該字串轉換為數字 等於 0 ";}//output:該字串轉換為數字 等於零。 這是關鍵的一個例子手冊上有解釋:該值由字串最前面的部分決定。如果字串以合法的數字資料開始,就用該數字作為其值,否則其值為 0(零)。 也就是說 '3asfdf'==3 ; 'adsfasdf'==0 相當要注意$a=0;if($a==''){ echo "0 等於
Time of Update: 2016-07-25
ignore_user_abort(true);set_time_limit(0);function write_txt(){if(!file_exists(”test.txt”)){$fp = fopen(”test.txt”,”wb”);fclose($fp);}$str = file_get_contents(’test.txt’);$str .= “\r\n”.date(”H:i:s”);$fp =