Time of Update: 2016-07-25
/* Person.class.php */ class Person { public $name; public $age; function __construct ($name, $age) { $this->name = $name; $this->age = $age; } }
Time of Update: 2016-07-25
/** * Validator for Login. */final class LoginValidator { private function __construct() { } /** * Validate the given username and password. * @param $username and $password to be validated * @return array array of
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
private static $_instance; 複製代碼2)、建構函式和複製函數必須聲明為私人的,防止外部程式new類從而失去單例模式的意義: private function __construct() { $this->_db = pg_connect('xxxx'); } private function __clone() { }//覆蓋__clone()方法,禁止複製 複製代碼(3).
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
$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
//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
foreach (getallheaders() as $name => $value) { echo "$name: $value\n"; } ?> 複製代碼不過這個函數只能在apache環境下使用,iis或者nginx並不支援,可以通過自訂函數實現。 if (!function_exists('getallheaders')) { function getallheaders() {
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
/** 控制器: @link jbxue.com*/class DemoController { function index() { echo('hello world'); } } /* End of file democontroller.php */複製代碼以上檔案只是建立了一個名為DemoController的對象並包含一個index的方法,該方法輸出hello world。下面在index.php中執行DemoController中index方法。 檔案:index.php
Time of Update: 2016-07-25
RewriteEngine On RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.+) index.php/$1 [L] 複製代碼
Time of Update: 2016-07-25
{some_text} {some_more_text}複製代碼它們在文檔中沒有意義,它們代表的意義只是PHP將用其他的東西來替換它。如果你同意這種對視圖的鬆散描述,你也就會同意絕大多數模板方案並沒有有效分離視圖和模型。模板標籤將被替換成什麼存放在模型中。在你實現視圖時問自己幾個問題:“全體視圖的替換容易嗎?”“實現一個新視圖要多久?” “能很容易的替換視圖的描述語言嗎?(比如在同一個視圖中用SOAP文檔替換HTML文檔)”二、模型(Model)
Time of Update: 2016-07-25
function server_transfer($dest){global ...; // 把希望在新頁面中用到的本頁變數或自訂的全域變數列在這裡include $dest; // 運行新指令碼exit; // 退出本指令碼}?> 複製代碼注意:1)、如果跳轉之前輸出的任何資料都會在新頁面中顯示,除非使用 ob_start 緩衝,可以在跳轉之前清空,這樣就互不影響了。2)、由於新頁面在一個自訂的函數範圍內運行,所以本頁面定義的變數不會影響到新頁面,這點是好處也是壞處。3)、新頁面依然可以用 $
Time of Update: 2016-07-25
$file = fopen("contacts.csv","r"); print_r(fgetcsv($file)); fclose($file); ?>複製代碼CSV 檔案: George, John, Thomas, USA James, Adrew, Martin, USA 輸出類似: Array ( [0] => George [1] => John [2] => Thomas [3] => USA )例2: $file = fopen("contacts.csv","r"
Time of Update: 2016-07-25
function ip_test($ip,$iprule){ $ipruleregexp=str_replace('.*','ph',$iprule); $ipruleregexp=preg_quote($ipruleregexp,'/'); $ipruleregexp=str_replace('ph','\.[0-9]{1,3}',$ipruleregexp); if(preg_match('/^'.$ipruleregexp.'$/',$ip))
Time of Update: 2016-07-25
DHTML技術各項功能的實現都依賴於使用用戶端指令碼與瀏覽器宿主及在宿主中輸出的Web頁面之間的互動,這種互動是通過對象這個技術手段實現的。DHTML技術各項功能的實現都依賴於使用用戶端指令碼與瀏覽器宿主及在宿主中輸出的Web頁面之間的互動,這種互動是通過對象這個技術手段實現的。BOM與DOM的區別 # DHTML技術各項功能的實現都依賴於使用用戶端指令碼與瀏覽器宿主及在宿主中輸出的Web頁面之間的互動,這種互動是通過對象這個技術手段實現的。# BOM即Browser Object
Time of Update: 2016-07-25
$arr1 = $dblink->mem_fetch_array ( "SELECT t_pid,imgname,invented,score FROM `t_sum_giftimg` where t_pid=3 or t_pid=6", 0 ); $arr2 = $dblink->mem_fetch_array ( "SELECT t_pid,imgname,invented,score FROM `t_sum_giftimg` where t_pid=10 or t_pid=12", 0