0

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

例如,我做了三个搜索,只显示第三个结果——其余的都是空白的。

任何人都可以解释一下吗?

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();
}

}

}
4

1 回答 1

0

I've tried your code and it works just fine for me. So I have a few ideas as to why it doesn't work for you.

  • Since the foreach($domains as $domain) loop does unset($urls), if the loop using $urls is actually located outside the foreach, then it will only contain the last one.
  • You explode $domains on \n and then $domain on | which may suggest you have an odd input format, and it may not quite work as you had intended, so looking at $domains and $domain in your loop might shed some light into what you actually get from your input.

As far as I can tell the curl and preg_match works properly. So either you aren't doing all the curl calls (due to the unset) or your inputted list of domains doesn't get interpreted as you expected.

于 2012-08-09T12:16:31.363 回答