PHP的一個文法有關問題

來源:互聯網
上載者:User
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……
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.