Php writes an XML file encoding error. I have a video table. The data structure is as follows: I use the following program to read the table file and generate the XML file: include (conn. php); include (crop. php); $ xmlFile & nbsp; 123.xml; $ dom & nbsp; new & nbsp; DomDocument (1 php: An error occurred while writing an XML file.
I have a video table with the following data structure:
I use the following program to read table files and generate XML files:
Include ("conn. php ");
Include ("crop. php ");
$ XmlFile = "123.xml ";
$ Dom = new DomDocument ('1. 0', 'utf-8 ');
$ Dom-> formatOutput = true;
$ Thumbnails = $ dom-> createElement ("thumbnails ");
Mysql_select_db ('hdm0910283 _ db', $ lnk) or die ('Can \'t use hdm0910283_db:'. mysql_error ());
Mysql_query ("set names UTF-8 ");
$ SQL = "select * from video ";
$ Query = mysql_query ($ SQL );
While ($ row = mysql_fetch_array ($ query )){
// Cut youku
$ Imageurl = "../workshow/images/". $ row [imgname];
Cutphoto ("$ imageurl", "$ imageurl", 200,113 );
$ Dom-> appendChild ($ thumbnails );
$ Thumbnail = $ dom-> createElement ("thumbnail ");
$ Thumbnail-> setAttribute ('filename', $ row [imgname]);
$ Thumbnail-> setAttribute ('label', $ row [title]);
$ Thumbnail-> setAttribute ('URL', $ row [url]);
$ Thumbnails-> appendChild ($ thumbnail );
}
$ Dom-> save ($ xmlFile );
The following error is prompted during running:
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
I have tested data insertion and reading in tables. please help me solve this problem.
XML
------ Solution --------------------
Mysql_query ("set names utf8 ");
UTF-8 is invalid.