Foreach循环不正确

时间:2012-12-17 12:54:11

标签: php

在此抓取工具中,它会搜索并抓取bbc主页的所有链接。

当它找到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);

}}

1 个答案:

答案 0 :(得分:3)

在你的第二个foreach循环中,你指定$ ouput而不是$ output:

foreach ($ouput as $value) {

应该是:

foreach ($output as $value) {
相关问题