一段PHP代碼問題
PHP code
$url = "http://localhost/index.php/"."$string1"; $contents = file_get_contents($url);print_r($contents);
PHP code
$url = "http://localhost/index.php/"."$string1"; $contents = file_get_contents($url);//print_r($contents); if((preg_match_all('/(<\/table>)/iUs', $contents, $match))){ $contents = $match[1][0]; }print_r($contents);
為什麼這2段代碼列印出的結果是一樣的啊,這個網頁是
...結構的啊,其他類似的能成功截取,就是這個網頁列印出的結果和沒截取是一樣的。。。
------解決方案--------------------
給出你的頁面內容才行呀,這樣子你讓人怎麼猜? 有問題的肯定就是在正則咯
------解決方案--------------------
第二段正則的地方輸出看下
PHP code
if((preg_match_all('/(<\/table>)/iUs', $contents, $match))){ echo '333'; //測試下是否正則匹配到 $contents = $match[1][0]; var_dump($contents); //列印輸出看下 }
------解決方案--------------------
網頁是...結構。而 preg_match_all('/(<\/table>)/iUs 等於是匹配全部結構。
又 $contents = $match[1][0]; //如果頁面僅有一個... 結構。
那麼。跟file_get_contents()得出的結果不是一樣。是什嗎?
------解決方案--------------------
Regex有錯誤,改成:
preg_match_all('/
.*<\/table>/sU', $contents, $match)
------解決方案--------------------
preg_match('/<\/table>/is',$str,$m);
echo $m[0];
------解決方案--------------------
'">3,3'-二氯聯苯胺你入庫的資料沒有做轉義處理,所以出錯
mediumtext類型最大可存放 16M 字元,應該足夠了
------解決方案--------------------
$content=mysql_real_escape_string($contents[0]);
$SQL="INSERT INTO pagecontents (old_title,old_text) VALUES('{$string}','{$content}')";