項目中要用到採集的資料,所以就先拿CSDN部落格來試了試。這裡使用Simple HTML DOM(官網)這個庫,它能夠方便的遍曆HTML文檔。 find("#hotarticls ul.panel_body li a[title]");//取得id=hotarticls下class為panel_bodya的ul標籤下的a的title $span = $html->find("#hotarticls ul.panel_body li span");//取得span foreach(
不同的錯誤處理方法:簡單的die()語句自訂錯誤函數和錯誤觸發器錯誤報表基本的錯誤處理:使用die()函數if(!file_exists("welcome.txt")){ die("FIle not found");}else{ $file=fopen("welcome.txt","r");}或者$file=fopen("webdictionary.txt","r") or die("Unable to open
開啟檔案:fopen:fopen(filename,mode);//fopen("test.txt","r”);開啟模式:r 唯讀方式開啟,將檔案指標指向檔案頭 r+ 讀寫方式開啟,將檔案指標指向檔案頭 w 寫入方式,指向檔案頭,如果不存在則嘗試建立 w+ 讀寫方式,指向檔案頭,如果不存在則嘗試建立 a 寫入方式開啟,指向檔案末尾,如果不存在則嘗試建立
本文提供兩種方法,一種將小數變成字串,然後用”.“來截取,去.後的子字串長度。還有一種是講小數*10的N次方,比如10的8次方再對8次方取餘數,再不斷對10求餘,直到對10求餘的結果不為0。相比來說,第一種方法要好不少,理由是這樣的,比如1.000004在很邊界的時候或者0.99999這樣子PHP處理會有問題,會有誤差,導致得到的位元不一樣。而且精度難以把握,所以處理這種跟邊界有關的問題最後能用字串還是字串來做。第一種private function _getFloatLength($num)
str_replace(PHP 4, PHP 5)str_replace — Replace all occurrences of the search string with the replacement stringDescriptionmixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )This function returns a string or an
主要關注紅色標記語句即可。The include (or require) statement takes all the text/code/markup that exists in the specified file and copies it into the file that uses the include statement.Including files is very useful when you want to include the same PHP, HTML,
foreach(PHP 4, PHP 5)The foreach construct provides an easy way to iterate over arrays. foreach works only on arrays and objects, and will issue an error when you try to use it on a variable with a different data type or an uninitialized variable.