print_r语句似乎不起作用

问题描述 投票:0回答:3

我正在构建一个Web爬虫。它找到页面上的所有链接及其标题和元描述等。它确实很好。然后我写了一个数组,给出了我想要的链接的所有起始网址。因此,如果它抓取一个链接并且其url以给出起始URL的数组中的任何值开头,则插入$ news_stories。

唯一的问题是它似乎没有插入它们。该页面返回空白,现在它表示array_intersect语句需要一个数组,并且我没有指定我拥有的数组。

总之,我很难理解我的代码不起作用的地方以及为什么没有插入想要的URL。

$bbc_values = array(
    'http://www.bbc.co.uk/news/health-', 
    'http://www.bbc.co.uk/news/politics-', 
    'http://www.bbc.co.uk/news/uk-', 
    'http://www.bbc.co.uk/news/technology-',  
    'http://www.bbc.co.uk/news/england-', 
    'http://www.bbc.co.uk/news/northern_ireland-', 
    'http://www.bbc.co.uk/news/scotland-', 
    'http://www.bbc.co.uk/news/wales-', 
    'http://www.bbc.co.uk/news/business-', 
    'http://www.bbc.co.uk/news/education-', 
    'http://www.bbc.co.uk/news/science_and_enviroment-',         
    'http://www.bbc.co.uk/news/entertainment_and_arts-', 
    'http://edition.cnn.com/'
);

// BBC Algorithm
foreach ($links as $link) {
    $output = array(
        "title"       => Titles($link), //dont know what Titles is, variable or string?
        "description" => getMetas($link),
        "keywords" => getKeywords($link), 
        "link"        => $link                 
    );

    if (empty($output["description"])) {
        $output["description"] = getWord($link);
    }
}

$new_stories = array();

foreach ($output as $new_array) {
    if (array_intersect($output['link'], $bbc_values) == true) {
        $news_stories[] = $new_array;
    }

    print_r($news_stories);
}
php
3个回答
0
投票

你将数组分解为$ new_stories并打印$ news_stories ..... diff是'S'

检查代码是否进入此循环,我认为不...

if (array_intersect($output['link'], $bbc_values) == true) {
    echo 'here';
}

0
投票

嗯,我不认为array_intersect是你需要比较http://php.net/manual/en/function.array-intersect.php

也许你想寻找in_array http://php.net/manual/en/function.in-array.php


0
投票

使用return参数时,此函数使用内部输出缓冲,因此不能在ob_start()回调函数中使用。

© www.soinside.com 2019 - 2024. All rights reserved.