Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用PHP从数据库生成XML_Php_Xml - Fatal编程技术网

用PHP从数据库生成XML

用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 '<' */

我使用下面的代码从数据库生成一个非常大的XML文件 代码不是由我写的,而是由Jubba写的,可在Kirupa获得

问题是,所有内容的格式都很好,但大约有30'
$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 &lt;