用PHP从数据库生成XML
我使用下面的代码从数据库生成一个非常大的XML文件 代码不是由我写的,而是由Jubba写的,可在Kirupa获得 问题是,所有内容的格式都很好,但大约有30'用PHP从数据库生成XML,php,xml,Php,Xml,我使用下面的代码从数据库生成一个非常大的XML文件 代码不是由我写的,而是由Jubba写的,可在Kirupa获得 问题是,所有内容的格式都很好,但大约有30'$row['text']=str_replace(“$row['text']=str_replace(” <XYZ> <ab>123333</ab> <resource>http://xxx.com</resource> /XYZ> /* no '<' */
$row['text']=str_replace(“$row['text']=str_replace(”
<XYZ>
<ab>123333</ab>
<resource>http://xxx.com</resource>
/XYZ> /* no '<' */
header("Content-type: text/xml");
$host = "localhost";
$user = "root";
$pass = "";
$database = "test";
$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host.");
mysql_select_db($database, $linkID) or die("Could not find database.");
$query = "SELECT * FROM blog ORDER BY date DESC";
$resultID = mysql_query($query, $linkID) or die("Data not found.");
$xml_output = "<?xml version=\"1.0\"?>\n";
$xml_output .= "<entries>\n";
for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
$row = mysql_fetch_assoc($resultID);
$xml_output .= "\t<entry>\n";
$xml_output .= "\t\t<date>" . $row['date'] . "</date>\n";
// Escaping illegal characters
$xml_output .= "\t\t<text>" . $row['text'] . "</text>\n";
$xml_output .= "\t</entry>\n";
}
$xml_output .= "</entries>";
echo $xml_output;
?>
$row['text'] = str_replace("<", "<", $row['text']);
^----- should be <