在此爬網程序中,它搜索並爬網bbc主頁的所有鏈接。Foreach循環不正確
當它找到BBC新聞鏈接時,它將它們插入表格中。但由於某些原因,當腳本運行時,它並不像它應該那樣將它們插入到表中。
任何想法?
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);
}
}
foreach ($ouput as $value) {
if (substr($value, 0, 26) == "http://www.bbc.co.uk/news/") {
$data = '"' . implode('" , "', $value) . '"';
$success = mysql_query("INSERT INTO news_story (title, description , keywords, link)
VALUES (" . $data . ")");
print_r($data);
}}
很多的想法......什麼事情'的var_dump( $ output);'return?就在'foreach'循環之前。這個變量是否包含你期望的內容? – Jelmer
至少在'print_r($ data)'後輸出;' – slownage
請嘗試改正該錯字:'foreach($ ouput as $ value){'=>'foreach($ output as $ value){' – Pharaoh