Arkane Posted April 30, 2009 Share Posted April 30, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/156312-write-to-xml/ Share on other sites More sharing options...
mikesta707 Posted April 30, 2009 Share Posted April 30, 2009 Well I believe that the character entity for the TM symbol is ™ but I can't really help to much beyond that without seeing some code, to tell how your data is parsed. Quote Link to comment https://forums.phpfreaks.com/topic/156312-write-to-xml/#findComment-822977 Share on other sites More sharing options...
Arkane Posted April 30, 2009 Author Share Posted April 30, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/156312-write-to-xml/#findComment-823045 Share on other sites More sharing options...
harristweed Posted April 30, 2009 Share Posted April 30, 2009 The tm symbol is & # 8 4 8 2 (without the spaces) perhaps you could do a replace: $gameid=str_replace("search","™",$gameid); // search is what ever you have in the databse for tm Quote Link to comment https://forums.phpfreaks.com/topic/156312-write-to-xml/#findComment-823121 Share on other sites More sharing options...
harristweed Posted April 30, 2009 Share Posted April 30, 2009 $gameid=str_replace("search"," & # 8 4 8 2 ;",$gameid); // search is what ever you have in the databse for tm and thats why I put in the spaces Quote Link to comment https://forums.phpfreaks.com/topic/156312-write-to-xml/#findComment-823122 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.