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
//當為0時,關閉計劃任務return 1;?>複製代碼2,jbxue.php ignore_user_abort();//關掉瀏覽器,PHP指令碼也可以繼續執行.set_time_limit(0);// 通過set_time_limit(0)可以讓程式無限制的執行下去$interval=60*3;// 每隔3分鐘運行$ii=0;do{$run = include 'jhrw.conf.php';if(!$run) { file_put_contents("tasktest.txt","=
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
/*** 解決跨瀏覽器下載檔案,中文亂碼的問題* edit bbs.it-home.org*/$ua = $_SERVER["HTTP_USER_AGENT"];$filename = "中文 檔案名稱.txt";$encoded_filename = urlencode($filename);$encoded_filename = str_replace("+", "%20", $encoded_filename);header('Content-Type:
Time of Update: 2016-07-25
檔案上傳下載-bbs.it-home.org$dir = 'upload/';if(is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if($file!="." && $file!="..") { echo "".$file.""; } } closedir($dh);}}?>複製代碼2,上傳檔案原始碼
Time of Update: 2016-07-25
本文介紹下,在windows環境中,更改php.ini檔案的載入路徑的方法,有需要的朋友,參考下吧。在windows下,更改php.ini載入路徑,只要在WEB伺服器設定檔裡增加一段代碼就可以了。以apache伺服器以例,找到apache設定檔http.conf,尋找”ServerRoot “E:/phpserver/apahce”“換行,增加:PhpIniDir “E:/phpserver/php”重啟apache,查看phpinfo()函數,第7行即可看到載入的路徑。就是這樣的簡單,呵呵。&
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
一.記憶體溢出解決方案在做資料統計分析時,經常會遇到大數組,可能會發生記憶體溢出,這裡分享一下我的解決方案。還是用例子來說明這個問題,如下:假定日誌中存放的記錄數為500000條,那麼解決方案如下:複製代碼
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
header("Content-type:application/vnd.ms-excel");header("Content-Disposition:attachment;filename=export_data.xls");echo "姓名"."\t";echo "繁體"."\t";echo "部落格"."\t";echo "\n";echo "jason"."\t";echo "@"."\t";echo
Time of Update: 2016-07-25
//函數1,二維數組去掉重複值function array_unique_fb($array2D){ foreach ($array2D as $v){ $v = join(",",$v); //降維,也可以用implode,將一維數群組轉換為用逗號串連的字串 $temp[] = $v; } $temp = array_unique($temp); //去掉重複的字串,也就是重複的一維數組 foreach ($temp as
Time of Update: 2016-07-25
ob_start();echo '1';ob_flush();//輸出php緩衝並重新整理echo '2';ob_flush();//輸出php緩衝並重新整理$cc = ob_get_contents();ob_end_clean();var_dump($cc);?>複製代碼輸出:12string(0) ""測試2: ob_start();echo '1';flush(); //輸出apache緩衝並重新整理echo '2';flush(); //輸出apache緩衝並重新整理$
Time of Update: 2016-07-25
output_buffering = Off 複製代碼3,php.ini為;output_handler = ob_gzhandlerzlib.output_compression = Off;zlib.output_compression_level = -1 複製代碼4,apache增加如下: AddOutputFilter DEFLATE html php js
Time of Update: 2016-07-25
本文介紹下,在php中開啟gzip頁面壓縮輸出的方法,供大家學習參考。有關在php中配置gzip壓縮的要點:1、預設php是不開啟zlib整站壓縮輸出的,而是通過對需要壓縮輸出的頁面使用ob_gzhandler函數實現,兩者只能二選一,否則會報錯。2、zlib.output_compression預設值為Off,你可以將其設定為On,或者output buffer
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
define('ABSPATH', dirname(__FILE__).'/');$cache = true;//Gzip壓縮開關$cachedir = 'gzip_cache/';//存放gz檔案的目錄,使用前建立,並賦予可寫入權限$gzip = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');$deflate = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate');$encoding = $
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 =
Time of Update: 2016-07-25
$unsafe_variable = $_POST['user_input'];mysql_query("INSERT INTO table (column) VALUES ('" . $unsafe_variable . "')");複製代碼這是因為使用者可以輸入類似VALUE“); DROP TABLE表; - ,使查詢變成: INSERT INTO table (column) VALUES('VALUE'); DROP TABLE