Time of Update: 2017-01-19
Parse error: syntax error, unexpected $end in script.php on line xx 調試了一會後發現產生錯誤的行是檔案中間某行 //$str .= "?>\n"; 想起來了 PHP 解譯器允許的結尾標記那行還可以用單行注釋,即 //$str .= "?>\n"; 被解釋成結尾標記前有注釋,注釋的內容是 //$str .= ",而 ?> 後面的 \n"; 會被解釋作 PHP 塊外的內容按 HTML 輸出出去!結果是給 $str
Time of Update: 2017-01-19
CakePHP架構首頁: http://www.cakephp.org/下載後匯入工程中,目錄結構如下圖(使用版本:1.1.19.6305)搭建PHP環境,這裡使用了AppServ2.5.9。 下載首頁
Time of Update: 2017-01-19
先看代碼: 複製代碼 代碼如下:<?php class StrictCoordinateClass { private $arr = array('x' => NULL, 'y' => NULL); function __construct() { print "StrictCoordinateClass is being created"; print "<br/>"; } function __destruct() { print
Time of Update: 2017-01-19
curl_close — 關閉一個curl會話 curl_copy_handle — 拷貝一個curl串連資源的所有內容和參數 curl_errno — 返回一個包含當前會話錯誤資訊的數字編號 curl_error — 返回一個包含當前會話錯誤資訊的字串 curl_exec — 執行一個curl會話 curl_getinfo — 擷取一個curl串連資源控制代碼的資訊 curl_init — 初始化一個curl會話 curl_multi_add_handle —
Time of Update: 2017-01-19
先看下面的代碼: 複製代碼 代碼如下:<?php $var1 = "#####"; $var2 = "&&&&&"; function global_references($use_globals) { global $var1, $var2; if (!$use_globals) { $var2 =&$var1; //1 } else { $GLOBALS["var2"] =&$var1; //2 } } global_references(false); echo "var2 is
Time of Update: 2017-01-19
<?php for ($i=10; $i>0; $i--) { echo $i; flush(); sleep(1); } ?> 按照php手冊裡的說法 該函數將當前為止程式的所有輸出發送到使用者的瀏覽器。 上面的這段代碼,應該隔一秒鐘輸出一次$i。但是實際中卻不一定是這樣。有可能是等了10秒鐘後,所有的輸出同時呈現出來。 好,我們來改一下這段代碼,改成 <?php ob_end_clean();//修改部分 for ($i=10; $i>0; $i--) {
Time of Update: 2017-01-19
這段時間在看《PHP和MySQL Web開發》一書看到str_replace講解,一段小提示寫到:可以為str_replace的三個都使用數組傳入,但講解比較簡單,於是決定自己的實驗一下該函數在各個參數傳入數組時的執行結果。 函數原型:mixed str_replace(mixed needle,mixed new_needle,mixed haystack[,int &count]);
Time of Update: 2017-01-19
採集回來的圖片img標籤中,有好多javascript指令碼和無用的資訊,必需過替換自己想要的,比如alt。先看看要過濾的內容,我隨便複製出來: 複製代碼 代碼如下: sdfsdfsdf<img alt=”3568df.com靚圖” src=”http://www.aaa.com/upimg /080330/120D1232295023X0.gif” src=”http://www.eee.com/upimg/080330 /120D1232295023X0.gif” width=1
Time of Update: 2017-01-19
1.驗證email: < ?php if (ereg("/^[a-z]([a-z0-9]*[-_\.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})?$/i; ",$email)){ echo “Your email address is correct!”;} else{ echo "Please try again!"; } ?>
Time of Update: 2017-01-19
在你的程式初始化時使用如下代碼: 複製代碼 代碼如下:<?php $Php2Html_FileUrl = $_SERVER["REQUEST_URI"]; $Php2Html_UrlString = str_replace("/", "", strrchr($Php2Html_FileUrl, "/")); $Php2Html_UrlQueryStrList = explode("@", $Php2Html_UrlString);
Time of Update: 2017-01-19
友好URL的實現(吐血推薦) 大家經常看到別的站的URL是這樣的吧? http://www.xxx.com/module/show/action/list/page/7 或者 http://xx.com/module/show/action/show/id/8.shtml 帶副檔名的 或者 http://xx.com/module/show/action/show/id/8?word=ss&age=11 這樣的吧 今天我就是公布下這種方法的實現,並獨立出最簡單的代碼
Time of Update: 2017-01-19
複製代碼 代碼如下:<?php $a = 1; $b = 2; if (1==1) { $andy = '帥哥'; } ?> 一般注釋的時候,用 複製代碼 代碼如下:<?php /* $a = 1; $b = 2; */ if (1==1) { $andy = '帥哥'; } ?> 調程式的時候,老要把後面的*/拿到前面去,很麻煩 複製代碼 代碼如下:<?php /**/ $a = 1; $b = 2; if (1==1) { $andy = '帥哥'; }
Time of Update: 2017-01-19
使用 eAccelerator 加密PHP程式 複製代碼 代碼如下:# /usr/local/bin/encoder 執行後會看到簡單的使用說明: 複製代碼 代碼如下:Usage: encoder [options] source_file_name encoder [options] source_file_name... encoder [options] source_directory_name... Options: -s suffix encode files only with
Time of Update: 2017-01-19
1.產生隨機字串函數 function random($length) { $hash = @#@#; $chars = @#abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz@#; $max = strlen($chars) - 1; mt_srand((double)microtime() * 1000000); for($i = 0; $i < $length; $i++) { $hash .= $chars[
Time of Update: 2017-01-19
base64+gzinflate壓縮編碼(加密)過的檔案通常是以 <? eval(gzinflate(base64_decode( 為頭的一個php檔案。以下我們給出了相關的編碼解碼(加密解密)代碼。 壓縮編碼(加密)代碼: 複製代碼 代碼如下:<?php function encode_file_contents($filename) { $type=strtolower(substr(strrchr($filename,'.'),1)); if('php'==$type &&
Time of Update: 2017-01-19
複製代碼 代碼如下:function bdir($dir,$typearr){ $ndir = scandir($dir); foreach ($ndir as $k => $v){ if ($v == '.' || $v == '..'){ continue; } if (filetype($dir.$v) == 'file'){ $arr = explode('.',$v); $type = end($arr); if (in_array($type,$typearr)){ echo
Time of Update: 2017-01-19
一、 在函數中,傳遞數組時使用 return 比使用 global 要高效,比如: function userloginfo($usertemp){ $detail=explode("|",$usertemp); return $detail; } $login=userloginfo($userdb); 比 function userloginfo($usertemp){ global $detail; $detail=explode("|",$usertemp); }
Time of Update: 2017-01-19
1.header()函數header()函數是PHP中進行頁面跳轉的一種十分簡單的方法。header()函數的主要功能是將HTTP協議標題(header)輸出到瀏覽器。header()函數的定義如下:void header (string string [,bool replace [,int
Time of Update: 2017-01-19
PHP樹-不需要遞迴的實現方法/** * 建立父節點樹形數組 * 參數 * $ar 數組,鄰接列表方式組織的資料 * $id 數組中作為主鍵的下標或關聯鍵名 * $pid 數組中作為父鍵的下標或關聯鍵名 * 返回 多維陣列 **/function find_parent($ar, $id='id', $pid='pid') { foreach($ar as $v) $t[$v[$id]] = $v; foreach ($t as $k => $item){ if( $item[$pid]
Time of Update: 2017-01-19
eval() 函數把字串按照 PHP 代碼來計算。該字串必須是合法的 PHP 代碼,且必須以分號結尾。如果沒有在代碼字串中調用 return 語句,則返回 NULL。如果代碼中存在解析錯誤,則 eval() 函數返回 false。文法eval(phpcode) 參數 描述 phpcode 必需。規定要計算的 PHP 代碼。