Time of Update: 2016-07-25
本文為大家列舉了php新手易犯的幾個小錯誤,供大家參考。1、header already sent 這個錯誤通常會在你使用HEADER的時候出現,他可能是幾種原因本文為大家列舉了php新手易犯的幾個小錯誤,供大家參考。1、header already
Time of Update: 2016-07-25
function get_http_response_code($theURL) { $headers = get_headers($theURL); return substr($headers[0], 9, 3); }?> 複製代碼get_headers的作用就是訪問一個遠程地址,把伺服器發送的HTTP頭以數組形式返回。而$header[0]則是伺服器返回的狀態代碼(如果不出意外的話狀態代碼應該都是第一個返回的)。排除重新導向的例子: /** * Fetches
Time of Update: 2016-07-25
class Test { public function __construct(){ $this->_log('start'); } public function __destruct () { $this->_log('finish'); } public function
Time of Update: 2016-07-25
$array = array('0' => array('3', 'one'),'1' => array('101', 'two'),'2' => array('12', 'three'),'3' => array('13', 'four'),'4' => array('1', 'five'),'5' => array('3',
Time of Update: 2016-07-25
$search = '~^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?~i';$url = 'http://www.php.net/pub/ietf/uri/#Related';$url = trim($url);preg_match_all($search, $url ,$rr);printf("輸出URL資料為:%s\n",var_export( $rr ,TRUE));/*各分組如下 $1 = http:
Time of Update: 2016-07-25
if (ini_get('magic_quotes_gpc')) { function stripslashesRecursive(array $array) { foreach ($array as $k => $v) { if (is_string($v)) { $array[$k] = stripslashes($v);
Time of Update: 2016-07-25
$a='11'; $b=11; if($a===$b) { echo '嚴格相等'; } else if($a==$b) { echo '相等'; } else { echo '不等'; } 複製代碼 運行結果為相等。下面說一下刪除數組中的元素的方法:舉例如下: $_POST=array("firstname"=>'f',"lastname"=>'j',"email"=>"fj@qq.com","password"=>"123",'rpassword'
Time of Update: 2016-07-25
function getIp(){ if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown")) $ip = getenv("HTTP_CLIENT_IP"); else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown")) $ip =
Time of Update: 2016-07-25
//php當前迴圈為1,迴圈由裡到外依次遞增,break預設為1,例如跳出第2層迴圈for ($i=0;$i foreach (array(1,2,3) as $val){ foreach (array(1,2,3) as $val){ echo "1層迴圈"; break 2; //跳出第2層迴圈 } echo "2層迴圈"; }
Time of Update: 2016-07-25
// 求和 function rsum($v, $w) { return $v; } // 求沉積 function rmul($v, $w) { return $v; } $a = array(1, 2, 3, 4, 5); $x = array(); $b = array_reduce($a, "rsum"); echo '
Time of Update: 2016-07-25
foreach (getallheaders() as $name => $value) { echo "$name: $value\n"; } ?> 複製代碼不過這個函數只能在apache環境下使用,iis或者nginx並不支援,可以通過自訂函數實現。 if (!function_exists('getallheaders')) { function getallheaders() {
Time of Update: 2016-07-25
function substring($str, $start, $length){ //比較好用字串截取函數$len = $length;if($length $str = strrev($str); $len = -$length;}$len= ($len $tmpstr = "";for ($i= $start; $i { if (ord(substr($str, $i, 1)) > 0xa0) { $tmpstr .= substr($str,
Time of Update: 2016-07-25
$headers = array(); foreach ($_SERVER as $key => $value) { if ('HTTP_' == substr($key, 0, 5)) { $headers[str_replace('_', '-', substr($key, 5))] = $value; } }?>
Time of Update: 2016-07-25
/*計算php程式已耗用時間*/function microtime_float(){list($usec, $sec) = explode(” “, microtime());return ((float)$usec + (float)$sec);}//開始計時,放在頭部$starttime = microtime_float();//結束計時,放在最底部$runtime = number_format((microtime_float() – $starttime),
Time of Update: 2016-07-25
/*** Passport 加密函數** @param string 等待加密的原字串* @param string 私人密匙(用於解密和加密)** @return string 原字串經過私人密匙加密後的結果*/function passport_encrypt($txt, $key) {// 使用隨機數發生器產生 0~32000 的值並 MD5()srand((double)microtime() * 1000000);$encrypt_key =
Time of Update: 2016-07-25
// ggarciaa at gmail dot com (04-July-2007 01:57)// I needed to empty a directory, but keeping it// so I slightly modified the contribution from// stefano at takys dot it (28-Dec-2005 11:57)// A short but powerfull recursive function// that works
Time of Update: 2016-07-25
/*只支援整數的小寫金額轉中文大寫*/class ChineseNumber{//var $basical=array(0=>"零","一","二","三","四","五","六","七","八","九");var $basical=array(0=>"零","壹","貳","三","肆","伍","陸","柒","捌","玖");//var $advanced=array(1=>"十","百","千");var $advanced=array(1=>"拾","佰","仟")
Time of Update: 2016-07-25
if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) { $onlineip = getenv('HTTP_CLIENT_IP');} elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) { $onlineip =
Time of Update: 2016-07-25
class User { static function getInstance() { if (self::$instance == NULL) { // If instance is not created yet, will create it. self::$instance = new User(); } return self::$instance; } private function __construct() //
Time of Update: 2016-07-25
@ubuntu:/$ mkdir /usr/local/redis@ubuntu:/$ cd /usr/local/redis@ubuntu:/$ wget http://redis.googlecode.com/files/redis-2.4.2.tar.gz@ubuntu:/$ tar xzf redis-2.4.2.tar.gz@ubuntu:/$ cd redis-2.4.2@ubuntu:/$ make@ubuntu:/$ src/redis-server複製代碼redis測試命令: