Home > Backend Development > PHP Tutorial > php写xml文件问题

php写xml文件问题

WBOY
Release: 2016-06-23 14:05:55
Original
871 people have browsed it

<?phpinclude("conn.php");include("crop.php");mysql_select_db('hdm0910283_db', $lnk) or die ('Can\'t use hdm0910283_db : ' . mysql_error());mysql_query("SET NAMES gbk");	$sql="select * from video";$query=mysql_query($sql);$str="<thumbnails>";while ($row = mysql_fetch_array($query)) {	//echo $row[imgname];	$imageurl="../workshow/images/".$row[imgname];    cutphoto("$imageurl","$imageurl",200,113);	$str=$str."<thumbnail filename=\"".$row[imgname]."\" label=\"".$row[title]."\" url=\"".$row[url]. "\"/>";	//echo $row[imgname];}header("content-type:text/html; charset=utf-8");    //指定PHP使用UTF-8编码$xml = simplexml_load_file("../workshow/xml/thumbnails.xml");        //读取xml文件$str = $xml->asXML();                              //标准化$xml$fp = fopen("../workshow/xml/thumbnails.xml", "w");                      //新建xml文件fputs($fp, $str);                                     //写入-------xml文件fclose($fp);?>
Copy after login

我就是想用PHP写一个xml文件,但后发现,每次都写完之后xml文件都没有变化,数据库读取没有问题,问题出在哪呢?
以下是xml文件,中间的label有点乱码
<?xml version="1.0"?><thumbnails><thumbnail filename="136421249467911.jpg" label="&#x94C1;&#x519B;-&#x7EAA;&#x5FF5;&#x957F;&#x6625;&#x51C0;&#x6708;&#x9AD8;&#x65B0;&#x533A;&#x57CE;&#x5E02;&#x7BA1;&#x7406;&#x884C;&#x653F;&#x6267;&#x6CD5;&#x5C40;&#x6210;&#x7ACB;" url="http://v.youku.com/v_show/id_XNTI5NzU4MzEy.html"/><thumbnail filename="136421346392337.jpg" label="&#x90A3;&#x4E00;&#x5E74; &#x8FD9;&#x4E00;&#x5E74;-&#x540C;&#x5B66;&#x4F1A;&#x7EAA;&#x5FF5;" url="http://v.youku.com/v_show/id_XNTI5NjEwMzMy.html"/><thumbnail filename="136421349294580.jpg" label="&#x677E;&#x539F;&#x7CAE;&#x98DF;&#x96C6;&#x56E2;&#x6709;&#x9650;&#x516C;&#x53F8;" url="http://v.youku.com/v_show/id_XNTI5Njk2MzQ0.html"/><thumbnail filename="136421354756516.jpg" label="&#x751F;&#x6001; &#x9B45;&#x529B; &#x548C;&#x8C10; &#x957F;&#x767D;&#x5C71;" url="http://v.youku.com/v_show/id_XNTI5Njg1OTEy.html"/><thumbnail filename="136421359617912.jpg" label="&#x5357;&#x90E1;&#x6C34;&#x4E91;&#x5929;3&#x53F7;" url="http://v.youku.com/v_show/id_XNTI5NjcyMDM2.html"/><thumbnail filename="136421362461256.jpg" label="&#x5409;&#x6797;&#x7701;&#x677E;&#x539F;&#x519C;&#x4E1A;&#x9AD8;&#x65B0;&#x6280;&#x672F;&#x5F00;&#x53D1;&#x533A;" url="http://v.youku.com/v_show/id_XNTI5NjAwNzQw.html"/><thumbnail filename="136421365264950.jpg" label="&#x957F;&#x6625;&#x5174;&#x9686;&#x7EFC;&#x5408;&#x4FDD;&#x7A0E;&#x533A;" url="http://v.youku.com/v_show/id_XNTI5NTg4MDI0.html"/></thumbnails>
Copy after login


回复讨论(解决方案)

循环中
$str=$str." 但循环外还有
$str = $xml->asXML();
那么,缓存的查询结果不就被覆盖了吗?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template