Jump to content

Write to XML


Arkane

Recommended Posts

I need some help to output the data from a MySQL database to on XML file.

At the moment I have it done using fwrite because I need it all to be in UTF-8, but I keep running into problems.

If I use htmlentities or htmlspecialchars then TM symbols do not get written into the file, which are needed.  On the other hand, if I don't use htmlentities, the TM symbols work, but the xml is not valid because & symbols are not converted.

What can I do to make this work?

Link to comment
https://forums.phpfreaks.com/topic/156312-write-to-xml/
Share on other sites

Here's a bit of the code.  I've trimmed it down, but its pretty much all the same, just there are more fields used in the complete.

$i=0;
while ($i < $num) {
$gameid=mysql_result($result,$i,"gameid");
$title=mysql_result($result,$i,"title");
$short=mysql_result($result,$i,"abbrev");

$xmlud = fopen($xml, 'a') or die("can't open file");

fwrite($xmlud, utf8_encode("	<game name=\"".htmlspecialchars($gameid)."\">\r\n"));
fwrite($xmlud, utf8_encode("		<title>".htmlspecialchars($title, ENT_NOQUOTES)."</title>\r\n"));
fwrite($xmlud, utf8_encode("		<short-title>".htmlspecialchars($short, ENT_NOQUOTES)."</short-title>\r\n"));
fwrite($xmlud, utf8_encode("	</game>\r\n"));

fclose($xmlud);

$i++;
}

The actual offending field is the gameid field.  When it pulls the data from MySQL it has the sybols and the like as needed, it just doesnt write them into the file.

Link to comment
https://forums.phpfreaks.com/topic/156312-write-to-xml/#findComment-823045
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.