Time of Update: 2016-07-25
//a$arr=array('a'=>'abc','b'=>123,'c'=>true);//b//$arr=range('a','d');//1for($i=0;$iecho $arr[$i].', ';echo '';//2foreach($arr as $key)echo "$key, ";echo '';//3foreach($arr as $key=>$val)echo "$key-$val, ";echo
Time of Update: 2016-07-25
$a = array( 'a',);$b = array( 'u',);$c = $a + $b;var_dump($c);複製代碼輸出: $a = array( 66=>'a',);$b = array( 60=>'u', 66=>'c');$c = $a + $b;var_dump($c);複製代碼輸出: $a = array( 1=>'a', 2=>'b', 'c'=>'c', 'd'=>'d',);$b = array( 1=>
Time of Update: 2016-07-25
/*** 檔案下載* 多種檔案格式,包括pdf、zip、gif、jpg、mpeg、word等。* edit bbs.it-home.org*/function dl_file($file){ //First, see if the file exists if (!is_file($file)) { die("404 File not found!"); } //Gather relevent info about file $len = filesize($file);
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
function &func(){ return "";}複製代碼2.在調用時,在函數前增加引用符號。 $return = &func();複製代碼PHP的範圍只有兩種1, 函數外,全域範圍。2, 函數內,局部範圍。法則:範圍不重疊。(全域不能訪問局部,局部不能訪問全域)但是js是可重疊的。特殊的:預定義變數(9大超全域陣列變數)--注意是陣列變數。超全域:超級全域:既可以在全域使用,也可以在局部使用。所有的範圍都生效。 $_GET['v1'] = "123";echo $_GET['v1'
Time of Update: 2016-07-25
/*** php操作xml檔案* edit bbs.it-home.org*///例1$xml = simplexml_load_file('example.xml'); //建立SimpleXML對象var_dump($xml); //輸出XML//例2$xml = simplexml_load_file('example.xml'); //讀取XML檔案foreach($xml->depart as $a) //迴圈讀取XML資料中的每一個depart標籤{echo "$a->name ";
Time of Update: 2016-07-25
register_global = offmagic_quotes_gpc = offdisplay_error = offlog_error = on# allow_url_fopen = offexpose_php = offopen_basedir =safe_mode = ondisable_function =
Time of Update: 2016-07-25
//__set()方法用來設定私人屬性 public function __set($name,$value){ $this->$name = $value; } //__get()方法用來擷取私人屬性 public function __get($name){ return $this->$name;
Time of Update: 2016-07-25
/*** 瀏覽目錄中檔案* edit bbs.it-home.org*/$dir = dirname(__FILE__);$open_dir = opendir($dir);echo "";echo "檔案名稱大小類型修改日期";while ($file = readdir($open_dir)) {if ($file!= "." && $file != "..") {echo "" . $file . "";echo "" . filesize($file) . "";echo "" .
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 “”;
Time of Update: 2016-07-25
適合php初學者的一些基礎知識,也可算是一些經驗積累吧,有需要的朋友,可以參考下。PHP基礎一、初識PHPPHP是與HTML混合使用的嵌入式語言。1、PHP標記預設標記 短標記,需在php.ini中將short_open_tag選項開啟 短標記和其他標記不提倡使用2、關鍵字不區分大小寫,使用者自訂的類名和函數名不區分大小寫,變數名區分大小寫3、輸出boolean print(參數) 返回布爾值void echo(參數)
Time of Update: 2016-07-25
php檔案下載_bbs.it-home.org set_time_limit(24*60*60); if (!isset($_POST['submit'])) die (); $destination_folder = './down/'; // 檔案夾儲存下載檔案。必須以斜杠結尾 $url = $_POST['url']; $newfname = $destination_folder.basename($url);
Time of Update: 2016-07-25
class Foo{const con_var="常量屬性的值不能被修改";public function method_a(){echo (self::con_var);}}echo(Foo::con_var);$myFoo=new Foo();echo
Time of Update: 2016-07-25
// 結果出錯// 在調用 header() 之前已存在輸出header('Location: url');?>複製代碼二:禁用瀏覽器緩衝 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");header("Cache-Control: no-cache");header("Pragma: no-cache");複製代碼三:提示儲存一個產生的 PDF 檔案(Content-Disposition
Time of Update: 2016-07-25
/** * php 驗證碼 可自訂大小 * edit bbs.it-home.org*/function vCode($num=4,$size=20, $width=0,$height=0){!$width && $width = $num*$size*4/5+5;!$height && $height = $size + 10;// 去掉了 0 1 O l 等$str =
Time of Update: 2016-07-25
$_COOKIE["counter"]?($c=$_COOKIE["counter"]+1):($c=1);setCookie("counter",$c,time()+60);echo "歡迎您第"."".$c."次訪問cookie";//by bbs.it-home.org?>複製代碼下面是有關這個例子的代碼說明,供大家參考。以上代碼中,首先,瀏覽器請求一個資源(這個php頁面),發送下面的HTTP包頭內容到伺服器: GET http://localhost/index.php HTTP/1.
Time of Update: 2016-07-25
void ob_start(void);?>複製代碼告訴PHP處理器把所有的輸出重新導向到一個內部的緩衝(buffer)中。在調用ob_start之前,沒有輸出會被送到瀏覽器去。 string ob_get_contents(void);?>複製代碼該函數將“輸出緩衝”(output buffer)以字串的形式返回。你可以調用該函數把積累下來的輸出送到瀏覽器中。(僅在把buffering功能關閉之後!!) int ob_get_length(void);?>複製代碼返回緩衝中的字串的長度。
Time of Update: 2016-07-25
unserialize(iconv('gbk','utf-8',serialize($array))); 複製代碼結果是空白的。藉助var_export函數,最終函數如下: function array_iconv($in_charset,$out_charset,$arr){ return eval('return '.iconv($in_charset,$out_charset,var_export($arr,true).';'));}
Time of Update: 2016-07-25
$i = 3;ob_start();while ($i--) { echo $i, ""; ob_flush(); flush(); sleep(1);}ob_end_clean();?> 複製代碼問題:這段代碼不能每隔一秒輸出呢?原因分析:apache運行原理:當訪問一個地址(發送請求)後,在apache伺服器中啟動PHP,php執行是頁面級的,如果有可執行檔代碼:它全部執行完後再丟給apache,apache再丟給browser顯示結果。解決方案:如果是cli