私はphpのSQLクエリからxmlにデータを取得することに深刻な問題があります。私はいつもエラーを受け取ります:StartTag: invalid element name. The Start-Element is a Number
、私はそれが重要かどうか知りませんか?php parse xml - エラー:StartTag:無効な要素名
多分あなたが私を助けることができます!
PHP:
$query = "SELECT r.object_id,
t.term_taxonomy_id,
t.term_id,
t.taxonomy,
t.description,
p.post_date_gmt,
p.post_content,
p.post_title,
p.post_excerpt
FROM wp_posts p,
wp_term_taxonomy t,
wp_term_relationships r
WHERE r.object_id= p.id
AND t.term_taxonomy_id = r.term_taxonomy_id
AND p.post_status = 'publish'
AND p.post_type = 'post'
AND to_days(p.post_date_gmt) >= to_days(now()) - 120
ORDER BY p.post_date DESC";
// DB Connect
$connection = mysql_connect($server, $user, $password);
mysql_select_db($dbName, $connection);
$res = mysql_query($query);
// XML Output
$xml = '<?xml version="1.0" encoding="UTF-8"?>
<standing version="1.0">';
while ($row = mysql_fetch_assoc($res)){
$xml .= '
<'.$row['object_id'].'>
<term_taxonomy>'.$row['taxonomy'].'</term_taxonomy>
<description>'.$row['description'].'</description>
<post_date>'.$row['post_date_gmt'].'</post_date>
<post_content>'.$row['post_content'].'</post_content>
<post_title>'.$row['post_title'].'</pst_title>
<post_exerpt>'.$row['post_exerpt'].'</post_exerpt>
</'.$row['object_id'].'>
';
}
$xml.= '</standing>';
// Write to file
$file = 'News.xml';
if(is_file($file)) unlink($file);
$fp = fopen($file, "w+");
fwrite($fp, $xml);
fclose($fp);
mysql_close ($connection);
?>