0
嗨我已经构建了一个数组,并在完成脚本的最后过程中。更改PHP阵列
我一直在建立一个网络爬虫扫描指定网站上的特定链接。爬虫将所有链接存储在一个页面中,然后将它们插入另一个数组(news_stories)中,并在其中指定链接。
现在新数组的结构是这样的。
Array
(
[0] => Array
(
[title] => The Qlick
[description] => Qlick
[keywords] => Search Engine, Web, Sexy, Noah Smith
[link] => http://www.theqlick.com/qlickdates.php
)
)
这对我来说是困难的,它会插入并插入到mysql表中。现在我的代码使用函数来为它找到的每个链接抓取标题,描述等,然后将它们插入到新数组中,如果它们匹配的话。
反正有没有得到这个删除的磁盘阵列()在阵列的顶部,只是有指定标题的数组,描述等 我希望输出的样子:
[0] => Array
(
[title] => The Qlick
[description] => Qlick
[keywords] => Search Engine, Web, Sexy, Noah Smith
[link] => http://www.theqlick.com/qlickdates.php
)
有什么建议吗?
$bbc_values = array('http://www.theqlick.com/festivalfreaks.php', 'http://www.theqlick.com/qlickdates.php');
$news_stories = array();
foreach ($links as $link) {
$item = array(
"title" => Titles($link),
"description" => getMetas($link),
"keywords" => getKeywords($link),
"link" => $link
);
if (empty($item["description"])) {
$item["description"] = getWord($link);
}
foreach($bbc_values as $bbc_value) {
// note the '===' . this is important
if(strpos($item['link'], $bbc_value) === 0) {
$news_stories[] = $item;
}
}
}
$data = '"' . implode('" , "', $news_stories) . '"';
$query =
//CNN algorithm
print_r($news_stories);
为什么不移除第一个$ news_stories数组?当你打开它时,它是一个空的数组。然后,您只需使用$ news_stories []添加到数组中。只要做$ news_stories []会为你创建数组 – MrTechie
已经完成@MrTechie,似乎没有任何变化 –
你是什么意思?你想将阵列平铺到一个维度吗?你的输出会是什么样子? –