PHP的一個文法問題
PHP code
$contents = file_get_contents($url); if((preg_match_all('/(<\/table>)/iUs', $contents, $match))){$contents = $match[1][0];} else{ (preg_match_all('/(<\/ol>)/iUs',$contents,$match)) [color=#FF0000]$contents = $match[1][0];[/color]}
紅色那行報錯:
Parse error: syntax error, unexpected T_VARIABLE in
我這是要抓取網頁的部分資訊,網頁有2種架構,正則就是這2種,所以想做個判斷,不是第一種架構的正則就用第二種的正則來截取網頁資訊。
但是用if else文法報錯。
分開寫這2個正則的php代碼,這2個都沒錯,合在一起就錯了。不太瞭解PHP,求大家幫幫忙了。
------解決方案--------------------
(preg_match_all('/(<\/ol>)/iUs',$contents,$match)) <== 這裡缺少行結束符“;”
------解決方案--------------------
操作放到迴圈裡面去
$contents = '';
while($rows=mysql_fetch_array(mysql_query("select pl_title from pagelinks limit 1,10")))
{
$string=$rows['pl_title'];
$string1=urlencode($string);
$url = "http://localhost/index.php/"."$string1";
$contents = file_get_contents($url);
if((preg_match_all('/(<\/table>)/iUs', $contents, $match)))
{
$contents .= $match[1][0];
}
else
{
(preg_match_all('/(<\/ol>)/iUs',$contents,$match));
$contents .= $match[1][0];
}
}
探討
還有一個問題:
PHP code
if($rows=mysql_fetch_array(mysql_query("select pl_title from pagelinks limit 1,10"))){
$string=$rows['pl_title'];
$string1=urlencode($string);
}
echo $string;
$url = "htt……