Time of Update: 2017-01-13
*/$array=array("size"=>"xl","color"=>"gold"); //定義一個數組print_r(array_values($array)); //輸出數組所有的值/*定義和用法array_values()
Time of Update: 2017-01-13
$array=array('step one','step two','step three','step four'); //定義一個數組echo
Time of Update: 2017-01-13
in_array() 函數在數組中搜尋給定的值。文法in_array(value,array,type)*/ 代碼如下複製代碼 $os_list=array("mac","nt","irix","linux"); //定義數組if(in_array("irix",$os_list)) &
Time of Update: 2017-01-13
//$array=array(1,1,1,1,1,8=>1,4=>1,19,3=>13); //建立數組print_r($array); //輸出數組內容//$a=array('green','red','yellow'); //定義第一個數組$b
Time of Update: 2017-01-13
*/$array1=array("a"=>"green","red","blue");$array2=array("b"=>"green","yellow","red");$result=array_intersect($array1,$array2);//計算交集並賦值print_r($result);//$search_a
Time of Update: 2017-01-13
返回的數組中包括的四個元素:鍵名為 0,1,key 和 value。單元 0 和 key 包含有數組單元的鍵名,1 和 value 包含有資料。如果內部指標越過了數組範圍,本函數將返回 false。 */$sports = array( 'football' => 'good', 'swimming' => 'very www.111cn.net','running' => 'not good'); while (list($key,$value) =
Time of Update: 2017-01-13
php教程 ob_flush flush 輸出緩衝執行個體與說明*/ob_flush(); //flush();//function flush (){ echo(str_repeat(' ',256)); // check that buffer is actually set before flushing if (ob_get_length()){
Time of Update: 2017-01-13
$array = array('aa'=>1,'bb'=>2);function delete(&$array, $key) { if (!is_array($key)) { $key = array($key); } foreach ($key as $k) { unset($array[$k]); } $array = array_values($array);}print_r(
Time of Update: 2017-01-13
代碼如下:$ch = curl_init(); $c_url = 'http://www.111cn.net; $c_url_data = "product_&type=".$type.""; curl_setopt($ch, curlopt_url,$c_url); curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_returntransfer, true);
Time of Update: 2017-01-13
在php檢測數組長度的函數有sizeof count 下面看個簡單一實例*/$colorlist = array("apple"=>"red",
Time of Update: 2017-01-13
看一完整重複資料刪除數組執行個體 代碼如下複製代碼 //刪除數組中的一個元素 function array_remove_value(&$arr, $var){ foreach ($arr as $key => $value) { if (is_array($value)) { array_remove_value($arr[$key], $var); } else { $value = trim($value); if ($value == $var) {
Time of Update: 2017-01-13
代碼如下複製代碼 deletedir($dir){if (rmdir($dir)==false && is_dir($dir)) { if ($dp = opendir($dir)) { while (($file=readdir($dp)) != false) { if (is_dir($file)
Time of Update: 2017-01-13
/mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )個函數返回一個字串或在出現問題的所有搜尋給定的數組替換值替換。如果你不喜歡需要更換的規則(如Regex),你應該始終使用此函數,而不是ereg_replace()或preg_replace函數()。*/// provides: <body text='black'>$bodytag =
Time of Update: 2017-01-13
fp = fopen("test.txt", 'ab'); //from the endflock($fp,
Time of Update: 2017-01-13
addslashes: 字串加入斜線。 bin2hex: 二進位轉成十六進位。 chop: 去除連續空白。 chr: 返回序數值的字元。 chunk_split: 將字串分成小段。 convert_cyr_string: 轉換古斯拉夫字串成其它字串。 crypt: 將字串用 des 編碼加密。 echo: 輸出字串。 explode: 切開字串。 flush: 清出輸出緩衝區。 get_meta_tags: 抽出檔案所有 meta 標記的資料。 htmlspecialchars:
Time of Update: 2017-01-13
php教程 explode() 函數php string 函數定義和用法explode() 函數把字串分割為數組。文法explode(separator,string,limit)參數 描述 separator 必需。規定在哪裡分割字串。 string 必需。要分割的字串。 limit 可選。規定所返回的數組元素的最大數目。例子在本例中,我們將把字串分割為數組: 代碼如下複製代碼 <?php$str = "hello world. it's a
Time of Update: 2017-01-13
比較兩個字串是否相等,最常見的方法就是使用“===”來判斷,至於它和“==”的區別,簡單來說就是前者強調“identical”類型也要求一樣;後者要求“equal”,值相同就可以了,參考【1】。或者使用strcmp來判斷,但是這個能夠告訴你兩個字串是否相等,但是無法告訴你在那裡不同。我的思路是單字串分割為一個個字母(character),這樣比較就能精確知道在那個位置不同了。分隔字串,使用&ldquo
Time of Update: 2017-01-13
strstr("母字串", "子字串")用來尋找子字串在母字串中第一次出現的位置,並返回母字串中從子字串開始到母字串結束的部分。比如echo strstr("abcdefg", "e"); //將輸出 "efg" 如果未找到子字串,則返回空。因為能用來判斷一個字串中是否含有另外一個字串: 代碼如下複製代碼 $needle = "iwind"; $str =
Time of Update: 2017-01-13
1、用file_get_contents或者fopen、file、readfile等函數讀取url的時候,會建立一個名為$http_response_header的變數來儲存http響應的前序,使用fopen等函數開啟的資料流資訊可以用stream_get_meta_data來擷取。 2、php教程5中新增的參數context使這些函數更加靈活,通過它我們可以定製http請求,甚至post資料。 範例程式碼1: 代碼如下複製代碼 <?php $html =
Time of Update: 2017-01-13
在 php教程5.2 中,內建了filter 模組,用於變數的驗證和過濾。過濾變數等操作可以參看我原先提及的,這裡我們看下如何直接過濾使用者輸入的內容。fliter 模組對應的 filter_input 函數使用起來非常的簡單,例如我們過濾使用者輸入名為 sample 的 get 參數為整型,那麼可以這樣寫filter_input(input_get, "sample", filter_sanitize_number_int);filter_input