仅显示最后结果

时间:2012-05-26 23:00:04

标签: php regex foreach

我希望在多个网站上搜索单个数据。正确地提取数据,但它仅显示最后一个搜索案例。单个搜索工作正常。

例如,我进行了三次搜索,只显示了第三个结果 - 其余的都是空白。

有人可以解释一下吗?

if($_POST)
{

$domains = explode("\n", $_POST[domains]);
foreach($domains as $domain)
{
$domain = explode('|', $domain);
$domain = str_replace(array('http://','/'),'',$domain[0]);

echo '<b>Providing Data for '. $domain .'.. </br></br>';


unset($urls);
unset($url);
unset($blacklinka[1]);
unset($blacklinka);
unset($AskApache_result);
unset($regex);

$domainshort = str_replace('www.','',$domain);

$domainshortdash = str_replace('.','-',$domainshort);


$urls[] = 'http://data.alexa.com/data?cli=10&dat=snbamz&url=' . $domain;




$ch = curl_init();

    foreach($urls as $url)
{

curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;     rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
    curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_REFERER, 'http://www.google.com/');
    $AskApache_result = curl_exec ($ch);



$regex = '/LINKSIN NUM="(.+?)"/';
preg_match($regex,$AskApache_result,$blacklinka);
echo '</br>';
echo 'Indexed Backlinks: '. $blacklinka[1];

    echo '</br></br>';


    flush();
    ob_flush();
}

}

}

1 个答案:

答案 0 :(得分:0)

我已经尝试过你的代码,它对我来说效果很好。所以我有一些想法,为什么它不适合你。

  • 由于foreach($domains as $domain)循环unset($urls),如果使用$urls的循环实际位于foreach之外,那么它只会包含最后一个。
  • 您在$domains上展开\n,然后在$domain上展示|,这可能表明您的输入格式很奇怪,而且可能不像您预期​​的那样有效,因此,在循环中查看$domains$domain可能会对您从输入中获得的内容有所了解。

据我所知,curl和preg_match正常工作。因此,要么您没有进行所有卷曲调用(由于未设置),要么您输入的域名列表未按预期解释。

相关问题