代碼擴充擷取遠程主機socket資訊*/function getpeername(){ $remote_ip=$remote_port=0; //定義ip socket_getpeername($this->fd,$remote_ip,$remote_port); //返回主機資訊 return
函數原型:resource stream_context_create ([ array $options [, array $params ]] )看個執行個體//定義options數組$opts=array( 'http'=>array ( 'method'=>"get", 'header'=>"accept-language: enrn"
echo getcwd()."n"; //取得當前工作目錄echo "<br>";chdir('08'); //改變工作目錄echo getcwd() .
數 format 是轉換的格式,以百分比符號 ("%") 開始到轉換字元結束。下面的可能的 format 值:%% - 返回百分比符號 %b - 位元 %c - 依照 ascii 值的字元 %d - 帶符號十進位數 %e - 可續計數法(比如 1.5e+3) %u - 無符號十進位數 %f - 浮點數(local settings aware) %f - 浮點數(not local settings aware) %o - 八位元 %s - 字串 %x -
strpos() 函數返回字串在另一個字串中第一次出現的位置。如果沒有找到該字串,則返回 false。文法strpos(string,find,start)*/$str="hello
*/$hash_list=hash_algos(); //返回註冊的hash規則列表print_r($hash_list); //顯示結果/*建立檔案以計算雜湊值*/file_put_contents('example.txt', 'the quick brown fox jumped over
similar_text() Function Compute兩個字串的匹配字元的數目。該函數也可以計算兩個字串的相似性(以百分比計)。文法similar_text(string1,string2,percent)注釋:levenshtein() 函數比 similar_text() 函數更快。不過,similar_text() 函數通過更少的必需修改次數提供更精確的結果。下面看執行個體*/$str1="hello
*/$str="hello world"; //定義字串$result=str_word_count($str); //尋找單詞個數echo $result; &
$crud = array('中國|||我國|||大地', 'kelon|||lerke|||sb', 'sesscxx');$crud = join('|',$crud);$crud = str_replace('|||', '|', $crud);$pat = "/({$crud})/i";$txt = '我知道中國你是sdfex誰!!';preg_match/*_all*/($pat, $txt, $matches);var_dump($matches);/
convert_uudecode() 函數對 uuencode 編碼的字串進行解碼。文法convert_uudecode(string)*/$str=",2&5l;&/@=v]r;&0a `"; //定義uuencode編碼字串$result=convert_uudecode($str);
//參數'a..z'界定所有大小寫字母均被轉義echo addcslashes('foo[ ]','a..z'); //輸出:foo[ ]//$str="is your name o'reilly?"; //定義字串,其中包括需要轉義的字元echo
*/$array=array("size"=>"xl","color"=>"gold"); //定義一個數組print_r(array_values($array)); //輸出數組所有的值/*定義和用法array_values()
$array=array('step one','step two','step three','step four'); //定義一個數組echo
//$array=array(1,1,1,1,1,8=>1,4=>1,19,3=>13); //建立數組print_r($array); //輸出數組內容//$a=array('green','red','yellow'); //定義第一個數組$b
大家都知道,rename()函數可以對檔案或目錄進行重新命名的操作。其實它還可以做很多事情。熟悉unix的朋友應該知道shell命令mv,它相當與win32的移動,而且移動的同時可進行重新命名。我發現,php的rename()函數就相當於mv,它不僅僅只有簡單的重新命名的功能,同樣可以改變檔案甚至整個目錄的路徑。例如: $oldpath ----檔案或目錄原來路徑 $newpath ----新定義路徑 那麼 rename($oldpath,$newpath)就可以完成檔案/目錄移動的操作
很有用的一些函數,你可以作為源碼儲存,然後以後避免重複編寫。檔案讀取函式 //檔案讀取函式 function PHP_Read($file_name) { $fd=fopen($file_name,r); while($bufline=fgets($fd, 4096)){ $buf.=$bufline; } fclose(
<? echo "<p>__________________________<p>"; $string="242432反對感是456,,犯得上廣泛大使館地方7890abc"; $mb_strlen=mb_strlen($string); $len=20; echo $string."<p>"; echo "總長為:".($mb_strlen+1)."<p>"; echo "截取數:".$len."<p>";
ubuntu9.04系統如果使用 apache2, apache 的 configure 命令由:./configure –prefix=$(WWWHOME) –enable-module=so改成:./configure –prefix=$(WWWHOME) –enable-sophp 的 configure 命令:./configure –prefix=$(PHPHOME)
。下面是一個用於更新統計資料的樣本:$('#stats').load('stats.html'); 這段代碼,好像是只執行一次,我現在想實現資料即時更新,比如統計線上人數$.post('${base}/tagModelByTagId.shtml',
PHP and AJAX 仿 Live與google 搜尋方塊AJAX的Live搜尋在AJAX以下例子,我們將表現出生活的搜尋,那裡的伺服器獲得搜尋結果,同時使用者類型。 Live搜尋有許多好處,相比傳統的搜尋: 匹配結果表明您鍵入結果狹隘你繼續輸入如果結果變得過於狹窄,刪除字元看到一個更廣泛的結果這個例子包含了四個網頁: 一個簡單的HTML表單一個JavaScript 一個PHP網頁XML檔案在這個例子中,結果發現在一個XML檔案( links.xml )