$contents = file_get_contents($url); 
if((preg_match_all('/(<h1.*<\/table>)/iUs', $contents, $match))){
$contents = $match[1][0];

else{
(preg_match_all('/(<h1.*<\/ol>)/iUs',$contents,$match))
$contents = $match[1][0];
}红色那行报错:
Parse error: syntax error, unexpected T_VARIABLE in 我这是要抓取网页的部分信息,网页有2种框架,正则就是这2种,所以想做个判断,不是第一种框架的正则就用第二种的正则来截取网页信息。
但是用if else语法报错。
分开写这2个正则的php代码,这2个都没错,合在一起就错了。不太了解PHP,求大家帮帮忙了。

解决方案 »

  1.   

    本帖最后由 xuzuning 于 2012-03-26 15:51:36 编辑
      

  2.   


    $contents = file_get_contents($url);
    if((preg_match_all('/(<h1.*<\/table>)/iUs', $contents, $match))){
    $contents = $match[1][0];
    }
    else{
    (preg_match_all('/(<h1.*<\/ol>)/iUs',$contents,$match))
    $contents = $match[1][0]; }
      

  3.   

    还有一个问题:
    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 = "http://localhost/index.php/"."$string1";
    $contents = file_get_contents($url);
    if((preg_match_all('/(<h1.*<\/table>)/iUs', $contents, $match))){
    $contents = $match[1][0];
    }
    else{
    (preg_match_all('/(<h1.*<\/ol>)/iUs',$contents,$match));
    $contents = $match[1][0];
    }我想批量处理数据:select pl_title from pagelinks limit 1,10
    但是运行成功之后,数据库只存进去了第一条数据,而且打印echo $string;的值,也只出来从数据库里读出的第一个数据
      

  4.   

    操作放到循环里面去$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('/(<h1.*<\/table>)/iUs', $contents, $match)))
    {
    $contents .= $match[1][0];
    }
    else
    {
        (preg_match_all('/(<h1.*<\/ol>)/iUs',$contents,$match));
        $contents .= $match[1][0];
        }
    }
      

  5.   

    你只读了一条当然也只能出来一条$rs = mysql_query("select pl_title from pagelinks limit 1,10");while($rows=mysql_fetch_array($rs)) {
      //在这里逐条处理读出来的数据
    }
      

  6.   

    Fatal error: Maximum execution time of 30 seconds exceeded in:
    while($rows=mysql_fetch_array(mysql_query("select pl_title from pagelinks limit 14,2"))){while($rows=mysql_fetch_array(mysql_query("select pl_title from pagelinks limit 14,2"))){
    $string=$rows['pl_title'];
    $string1=urlencode($string);
    }
    echo $string;   //想打印出来看结果
    $url = "http://localhost/index.php/"."$string1";
    $contents = file_get_contents($url);
    if((preg_match_all('/(<h1.*<\/table>)/iUs', $contents, $match))){
    $contents = $match[1][0];
    }
    else{
    (preg_match_all('/(<h1.*<\/ol>)/iUs',$contents,$match));
    $contents = $match[1][0];
    }处理2条都会超时,奇怪啊,怎么办呢?
      

  7.   

    修改php.ini   找到max_execution_time = 30;  改大一点
      

  8.   

    这个试过了,可能要在代码里改,但是现在只是测试2条数据呀,用while就不行了;
    刚才用while试一条数据都超时了,貌似是一直循环第一条。