implode ステートメントを使用して、この配列をデータベースに挿入しようとしています。しかし、どこが間違っているのかを見つけるのに苦労しています。基本的に、以下の2つの関数を変換して文字列を返すことを検討しています:
function Titles($link) {
$str = file_get_contents($link);
if( strlen( $str )>0 ) {
preg_match_all( "/\<title\>(.*)\<\/title\>/", $str, $titles );
if (count($titles) > 1) {
return $titles[1];
}
}
return '';
}
function getMetas($link) {
$str1 = file_get_contents($link);
if (strlen($str1)>0) {
preg_match_all( '/<meta.*?name=("|\')description("|\').*?content=("|\')(.*?)("|\')/i', $str1, $description);
if (count($description) > 1) {
return $description[4];
}
}
}
$data = array();
foreach ($links as $link) {
$output = array(
"title" => Titles($link),
"link" => $link,
"description" => getMetas($link),
"keywords" => getKeywords($link)
);
if (empty($output["description"]))
{$output["description"] = getWord($link);
}
$data[] = $output;
}
print_r($data);
mysql_query("INSERT INTO scan (title, url, description, keywords) VALUES ('".implode("'),('",$data)."')");
if (!mysql_query()) {
echo "woops";
}
mysql_close($connect);