Home >Backend Development >PHP Tutorial > php写XML文件编码异常,求解答

php写XML文件编码异常,求解答

WBOY
WBOYOriginal
2016-06-13 12:48:08989browse

php写XML文件编码错误,求解答
我有一个video的表,数据结构如下:


我利用如下程序读取表中文件,生成XML文件:

<br />
include("conn.php");<br />
include("crop.php");<br />
<br />
$xmlFile = "123.xml";<br />
$dom = new DomDocument('1.0','utf-8');<br />
$dom->formatOutput=true;<br />
$thumbnails = $dom->createElement("thumbnails"); <br />
mysql_select_db('hdm0910283_db', $lnk) or die ('Can\'t use hdm0910283_db : ' . mysql_error());<br />
mysql_query("SET NAMES utf-8");    <br />
$sql="select * from video";<br />
$query=mysql_query($sql);<br />
while ($row = mysql_fetch_array($query)) {<br />
	//切割youku截图<br />
	$imageurl="../workshow/images/".$row[imgname];<br />
    cutphoto("$imageurl","$imageurl",200,113);<br />
	$dom -> appendChild($thumbnails); <br />
    $thumbnail = $dom->createElement("thumbnail");<br />
    $thumbnail->setAttribute('filename', $row[imgname]);<br />
    $thumbnail->setAttribute('label', $row[title]);<br />
    $thumbnail->setAttribute('url', $row[url]);<br />
	$thumbnails -> appendChild($thumbnail);<br />
}<br />
$dom->save($xmlFile);<br />


运行的时候提示如下错误:
arning: DOMElement::setAttribute() [domelement.setattribute]: string is not in UTF-8 in D:\AppServ\www\rj\control\xml_do.php on line 20

Warning: DOMDocument::save() [domdocument.save]: output conversion failed due to conv error, bytes 0xCA 0xD3 0xC6 0xB5 in D:\AppServ\www\rj\control\xml_do.php on line 24

我测试过表中数据插入和读出均无问题,请高手帮助解决。

XML
------解决方案--------------------
mysql_query("SET NAMES utf8"); 
utf-8是无效的
Statement:
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