Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.