Time of Update: 2016-07-25
不論是編譯自原始碼的版本還是預建立的php版本,都在預設情況下帶有一個PHP可執行檔。這個可執行檔可以被用來運行命令列的PHP程式。要在系統中找到這個可執行檔,要遵照下面的步驟:Windows :放在PHP主安裝目錄下,檔案名稱是php.exe或者(在老版本的PHP裡)是php-cli.exe。Linux :
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
/*** 一般檔案安全下載* edit bbs.it-home.org*/ $durl = 'file/phpcms2008_o2abf32efj883c91a.iso'; $filename = 'phpcms2008_o2abf32efj883c91a.iso'; $file = @fopen($durl, 'r'); header("Content-Type: application/octet-stream"); header(
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
本文介紹下,在windows環境中,定時自動執行php程式的設定方法,有需要的朋友參考下吧。步驟如下:單擊"開始"按鈕,然後依次選擇"程式"→"附件"→"系統工具"→"任務計劃"(或者是"設定"→"控制台"→"任務計劃"),啟動Windows
Time of Update: 2016-07-25
//所謂斷字 (word break),即一個單詞可在轉行時斷開的地方。這一函數將在斷字處截斷字串。// Please acknowledge use of this code by including this header.function myTruncate($string, $limit, $break=".", $pad="...") {// return with no change if string is shorter than
Time of Update: 2016-07-25
$my_array = array("a" => "Dog", "b" => "Cat", "c" => "Horse");krsort($my_array);print_r($my_array);?>複製代碼輸出: $my_array = array("a" => "Dog", "b" => "Cat", "c" => "Horse");asort($my_array);print_r($my_array);?>複製代碼輸出: Array( => Cat[a] => Dog[c] =>
Time of Update: 2016-07-25
/*** header與readfile函數應用舉例* 下載檔案 判斷許可權* edit bbs.it-home.org*/ $file = get_file_address();// 檔案的真真實位址(支援url,不過不建議用url) if (file_exists($file)) {header('Content-Description: File Transfer');header('Content-Type:
Time of Update: 2016-07-25
$a=20;$b = 6;echo ($a/$b).""; //out 3.3333333333333echo ceil($a/$b).""; //out 4echo floor($a/$b).""; //out 3echo round($a/$b).""; //out 3//by bbs.it-home.org?>複製代碼另外,為大家介紹下php取整數常用的四種方法。主要用到四個函數:ceil,floor,round,intval。1,ceil — 進一法取整說明float ceil (
Time of Update: 2016-07-25
//php定時計劃任務//by bbs.it-home.orgignore_user_abort(); // 函數設定與客戶機斷開是否會終止指令碼的執行set_time_limit(0); // 來設定一個指令碼的執行時間為無限長$interval=30;do{$fp = fopen(‘text3.txt’,'a’);fwrite($fp,’test’);fclose($fp);sleep($interval); //
Time of Update: 2016-07-25
ob_start(); //開啟緩衝區echo \"Hellon\"; //輸出header("location:index.php"); //把瀏覽器重新導向到index.phpob_end_flush();//輸出全部內容到瀏覽器//by bbs.it-home.org?>複製代碼所有對header()函數有瞭解的人都知道,這個函數會發送一段檔案頭給瀏覽器,但是如果在使用這個函數之前已經有了任何輸出(包括空輸出,比如空格,斷行符號和換行)就會提示出錯。如果我們去掉第一行的ob_start()
Time of Update: 2016-07-25
zlib.output_compression = Onzlib.output_compression_level = 6複製代碼完成後可以通過phpinfo()函數檢測結果,當zlib.output_compression的Local
Time of Update: 2016-07-25
$json_string='{"id":1,"name":"foo","email":"foo@jbxue.com","interest":["wordpress","php"]} ';$obj=json_decode($json_string);echo $obj->name; //prints fooecho $obj->interest[1]; //prints php複製代碼2,PHP解析XML 資料
Time of Update: 2016-07-25
/*** 遍曆並解析xml檔案為一個數組* edit bbs.it-home.org*/public function parseXML($menus){ $result = array(); foreach($menus as $menu){ $tmparr = array(); //處理空文本節點方式A if( $menu->nodeName !='#text'){ // 檢索子項目時跳躍過文本節點 - 處理空文本節點方式B
Time of Update: 2016-07-25
nginx中文手冊下載複製代碼2,檔案get.php,內容如下: /*** php實現檔案下載* edit bbs.it-home.org*/if (!isset(GET["file"]) || !isset(GET["type"])) { print "no file selsect"; exit(); }$file = GET["file"].".".GET["type"]; if (@$fp = fopen($file,'r')){ header ("Content-type:
Time of Update: 2016-07-25
/*** 遍曆二維數組* edit bbs.it-home.org*///for迴圈遍曆$arr2=array(array("張三","20","男"),array("李四","25","男"),array("王五","19","女"),array("趙六","25","女"));echo "姓名年齡性別";for($i=0;$iecho "";for($j=0;$j echo ""; echo $arr2[$i][$j]; echo "";}echo "";echo
Time of Update: 2016-07-25
extension=php_gd2.dll複製代碼找到php的設定檔php.ini,搜尋extension=php_gd2.dll,去掉前面的分號即可;如果沒有,請直接添加。這種情況適合於windows系統和編譯時間支援gd的php,儲存後重啟apache即可。如果是編譯安裝的,比如Ubuntu的deb或redhat的rpm安裝的php,則可以用命令安裝此擴充:形如下面這樣: Ubuntu:sudo apt-get install php5-gdredhat:yum install
Time of Update: 2016-07-25
exec(""/bin/ls -l"");exec(""/bin/ls -l"", $res);#$res是一個資料,每個元素代表結果的一行exec(""/bin/ls -l"", $res, $rc);#$rc的值是命令/bin/ls -l的狀態代碼。成功的情況下通常是0?>複製代碼passthru()原型:void passthru (string command [, int
Time of Update: 2016-07-25
/*** 驗證碼類* edit bbs.it-home.org*/class ValidationCode {private $width;private $height;private $codeNum;private $image; //映像資源private $disturbColorNum;private $checkCode;function __construct($width=80, $height=20,
Time of Update: 2016-07-25
/*** 匯出word格式文檔* 只添加一次關鍵詞連結* edit bbs.it-home.org*///var_dump($_SERVER["HTTPS"]);die;class word{function start(){ob_start();echo ‘xmlns:w=”urn:schemas-microsoft-com:office:word”xmlns=”http://www.w3.org/TR/REC-html40″>’;}function save($path){print “”;