Php 仅显示最后一个结果

Php 仅显示最后一个结果,php,regex,foreach,Php,Regex,Foreach,我正在寻找一个单一的数据块搜索多个网站。正在正确提取数据,但它仅显示最后一个搜索案例。一次搜索就可以了 例如,我进行了三次搜索,只显示第三个结果,其余结果为空 有人能解释一下吗 if($_POST) { $domains = explode("\n", $_POST[domains]); foreach($domains as $domain) { $domain = explode('|', $domain); $domain = str_replace(array('http://','/

我正在寻找一个单一的数据块搜索多个网站。正在正确提取数据,但它仅显示最后一个搜索案例。一次搜索就可以了

例如,我进行了三次搜索,只显示第三个结果,其余结果为空

有人能解释一下吗

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

}

}
if($\u POST)
{
$domains=explode(“\n”,$\u POST[domains]);
foreach($domains作为$domain)
{
$domain=分解(“|”,$domain);
$domain=str_replace(数组('http://','/'),''/'),'','$domain[0]);
echo“为“$domain.”提供数据,…

”; 未设置($URL); 未设置($url); 未结算($blacklinka[1]); 未结算($blacklinka); 未设置($AskApache_结果); 未结算($regex); $domainshort=str_replace('www.,'',$domain); $domainshortdash=str_replace('.','-',$domainshort); $URL[]='http://data.alexa.com/data?cli=10&dat=snbamz&url=“.$domain; $ch=curl_init(); foreach($url作为$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_超时,60); curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_REFERER,'http://www.google.com/'); $AskApache\u result=curl\u exec($ch); $regex='/LINKSIN NUM=“(.+?)”/”; preg_match($regex,$AskApache_result,$blacklinka); 回音“
”; echo“索引反向链接:”.$blacklinka[1]; 回音“

”; 冲洗(); ob_flush(); } } }
我试过你的代码,它对我来说很好。所以我有一些想法,为什么它不适合你

  • 由于
    foreach($domain as$domain)
    循环没有
    unset($url)
    ,如果使用
    $url
    的循环实际上位于foreach之外,那么它将只包含最后一个
  • 您在
    \n
    上分解
    $domain
    ,然后在
    |
    上分解
    $domain
    ,这可能表明您有一种奇怪的输入格式,并且它可能无法完全按照您的预期工作,因此查看循环中的
    $domains
    $domain
    ,可能会对您实际从输入中获得的内容有所了解

据我所知,卷曲和预配效果良好。因此,要么您没有执行所有的curl调用(由于未设置),要么您输入的域列表没有得到预期的解释。

检查preg\u match的返回值。另外,您正在取消顶部的$URL…您能给我们一些更完整的代码吗?哪里定义了
$url
?我添加了完整的代码,谢谢大家