$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,求大家帮帮忙了。
$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]; }
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;的值,也只出来从数据库里读出的第一个数据
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];
}
}
//在这里逐条处理读出来的数据
}
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条都会超时,奇怪啊,怎么办呢?
刚才用while试一条数据都超时了,貌似是一直循环第一条。