Time of Update: 2017-01-13
代碼如下複製代碼 function RecordToJson($recordset) { $jstr='['; while($rs = $recordset->Fetch())
Time of Update: 2017-01-13
is_file 只判斷檔案是否存在; 代碼如下複製代碼 <?php $file = "test.txt"; if(is_file($file)) { echo ("$file is a regular file"); }else { echo ("$file is not a regular file"); } ?> 輸出:test.txt is a regular
Time of Update: 2017-01-13
取部份字串。文法: string substr(string string, int start, int [length]);傳回值: 字串函數種類: 資料處理內容說明本函數將字串 string 的第 start 位起的字串取出 length 個字元。若 start 為負數,則從字串尾端算起。若可省略的參數 length 存在,但為負數,則表示取到倒數第 length 個字元。使用範例 代碼如下複製代碼 <?echo substr("abcdef"
Time of Update: 2017-01-13
代碼如下複製代碼 <?php/*** Check檢測類*/Class Check{ /** * IsUsername函數:檢測是否符合使用者名稱格式 * $Argv是要檢測的使用者名稱參數 * $RegExp是要進行檢測的正則語句 * 傳回值:符合使用者名稱格式返回使用者名稱,不是返回false */ function
Time of Update: 2017-01-13
1. 判斷Email: 代碼如下複製代碼 <?phpfunction is_email($email){return strlen($email) > 6 && preg_match("/^[w-.]+@[w-]+(.w+)+$/", $email);}?> 2. 判斷Url: 代碼如下複製代碼 function is_url($str){ return preg_match("
Time of Update: 2017-01-13
代碼如下: 代碼如下複製代碼 function get_between($input, $start, $end) { $substr = substr($input, strlen($start)+strpos($input, $start), (strlen($input) - strpos($input, $end))*(-1)); return
Time of Update: 2017-01-13
1.php 代碼如下複製代碼 <form name=form1 id=form1 method=post action=2.php>基本資料1:<input type=text name=base1 />基本資料2:<input type=text name=base2 /><input type=submit value="下一步"></form> 2.php 代碼如下複製代碼
Time of Update: 2017-01-13
下面程式運行結果為() 代碼如下複製代碼 ?$numb=array( array(10,15,30),array(10,15,30),array(10,15,30) ); echo count($numb,1);A.3B.12C.6D.9 答案:Bcount函數中如果mode被設定為 COUNT_RECURSIVE(或
Time of Update: 2017-01-13
.首先到http://phpmailer.worxware.com/ 下載最新版本的程式包2.下載完成後,找到class.phpmailer.php 、class.smtp.php兩個類放到自己的目錄下!3.然後建立一個php檔案這裡命名為:phpmail_jiucool.php4.phpmail_jiucool.php內容如下:執行個體 代碼如下複製代碼 function postmail_jiucool_com($to,$subject =
Time of Update: 2017-01-13
PHP Notice: Undefined variable PHP Notice: Undefined index看看吧,你有沒定義的變數直接使用了。不過編PHP的時候本來就不像C++那麼嚴格,編程的時候經常還會利用這個特點。PHP的預設設定是顯示這些提示,這會造成頁面無法正常顯示出來。 代碼如下複製代碼 //error_reporting(E_ALL); error_reporting(E_ALL || ~E_NOTICE); //顯示除去
Time of Update: 2017-01-13
所謂分頁顯示,也就是將資料庫中的結果集人為的分成一段一段的來顯示,這裡需要兩個初始的參數:每頁多少條記錄($PageSize)?當前是第幾頁($CurrentPageID)?現在只要再給我一個結果集,我就可以顯示某段特定的結果出來。至於其他的參數,比如:上一頁($PreviousPageID)、下一頁($NextPageID)、總頁數($numPages)等等,都可以根據前邊這幾個東西得到。以MySQL資料庫為例,如果要從表內截取某段內容,sql語句可以用:select * from
Time of Update: 2017-01-13
1.php中時間轉換函式 代碼如下複製代碼 strtotime(date())date("Y-m-d H:i",$unixtime) 2.php中獲得今天零點的時間戳記要獲得零點的unix時間戳記,可以使用$todaytime=strtotime(“today”),然後再使用date("Y-m-d H:i",$todaytime)轉換為日期。時間戳記轉換為日期
Time of Update: 2017-01-13
遍曆某檔案夾下的所有檔案和檔案夾,並且把所以匹配的檔案複製到同一目錄。下面例子把”/www/pooy/baike”目錄裡面的,所有html檔案都複製到”/www/pooy/bk”這個目錄下面。 代碼如下複製代碼 $dir="/www/pooy/baike"; static $dir_list =0; static $file_list =0; function
Time of Update: 2017-01-13
刪除指定檔案夾所有檔案 代碼如下複製代碼 $cacheDir = '../cache/runtime';$dh = opendir($cacheDir);while ( $file = readdir($dh) ) {if (($file == '.') || ($file == '..')) { continue; }if (file_exists( $cacheDir . '/' .$file)) {if (!unlink($cacheDir . '/' . $file)
Time of Update: 2017-01-13
例1 代碼如下複製代碼 <?php //密碼驗證 $password = "zongzi_Abc_oo13a2"; $n = preg_match_all("/^[a-zA-Zd_]{8,}$/",$password,$array); //長度是8或更多 var_dump($array); ?> 其它規則這裡就不舉例了大家可直接參閱 例子: Regex
Time of Update: 2017-01-13
如 代碼如下複製代碼 <?php$filename = "中文 檔案名稱.txt";header('Content-Type: application/octet-stream');header('Content-Disposition: attachment; filename=' . $filename);print "Hello!";?> 把程式儲存成UTF-8編碼再訪問,IE6下載的檔案名稱就會亂碼。
Time of Update: 2017-01-13
先利用trim系列函數來刪除左右空格 代碼如下複製代碼 <?phptrim 去除一個字串兩端空格, rtrim 是去除一個字串右部空格, ltrim 是去除一個字串左部空格。echo trim(" 空格 ")."<br>"; echo rtrim(" 空格 ")."<br>"; echo ltrim(" 空格 ")."<br>
Time of Update: 2017-01-13
mime_content_type返回指定檔案的MIME類型,用法: 代碼如下複製代碼 echo mime_content_type ( 'php.gif' ) . "n" ;echo mime_content_type ( 'test.php' ); 輸出:image/giftext/plain但是此函數在php5.3.0以後就不可用了,如果你是php5.3.0以後版本我們可使用 代碼如下複製代碼
Time of Update: 2017-01-13
PHP中常用的關鍵字final 1、final只能修飾類和方法,不能修飾成員屬性 作用:使用修飾的類不能被繼承,修飾的方法不能被覆蓋PHP 5 新增了一個 final 關鍵字。如果父類中的方法被聲明為final,則子類無法覆蓋該方法; 如果一個類被聲明為final,則不能被繼承。Example #1 Final 方法樣本 代碼如下複製代碼 <?phpclass BaseClass { public
Time of Update: 2017-01-13
我們常見一些網站在做ajax時返回JSON格式的資料:php輸出JSON格式顯然並非所願。還是字串,到底怎麼實現?其實很簡單,只要在php檔案頭部加入以下代碼: 代碼如下複製代碼 header('Content-type: text/json'); 範例程式碼: 代碼如下複製代碼 < ?phpheader('Content-type: text/json');$fruits = array (