rhamej Posted September 11, 2007 Share Posted September 11, 2007 I've never worked with a foreign language before, so I'm a little stuck. I built a simple backend that uploads data to a mySQL db using php. The Thai language shows fine in the html textarea no problem. However, I'm using php to create an XML file to yank the data into a Flash app. <?php $db = mysql_connect("localhost","XXXX","XXXX") or die("couldn't connect: " . mysql_error()); mysql_select_db("XXXX",$db) or die("no db: " . mysql_error()); header("Content-type: text/xml"); $xml_output = "<?xml version='1.0' encoding='utf-8' standalone='yes'?>\n<gallery>\n"; $sql = "SELECT * FROM gallery ORDER BY ID DESC"; $resultID = mysql_query($sql) or die (mysql_error()); while ($row=mysql_fetch_assoc($resultID)) { $xml_output .= "\t\t<item>\n"; $xml_output .= "\t\t<description1>".str_replace(" "," ",htmlentities($row['TITLE']))."</description1>\n"; $xml_output .= "\t\t<description2>".str_replace(" "," ",htmlentities($row['COMMENTS']))."</description2>\n"; $xml_output .= "\t\t<link>".htmlentities($row['SRC'])."</link>\n"; $xml_output .= "\t</item>\n"; } $xml_output .= "</gallery>\n"; echo $xml_output; ?> The Thai characters are getting stored as unicode in the db, like so: โรงขายยา The XML is writing it just like that as seen here: http://2210media.com/test2/xml.php , and Flash is seeing it just like that. Now Flash can not parse unicode so I need PHP to do it for me somehow. How do I get PHP to convert that to Thai? Thanks, Josh Quote Link to comment Share on other sites More sharing options...
Dragen Posted September 11, 2007 Share Posted September 11, 2007 try outputting the string like this: echo html_entity_decode($xml_output); It may or may not work.. Quote Link to comment Share on other sites More sharing options...
rhamej Posted September 11, 2007 Author Share Posted September 11, 2007 try outputting the string like this: echo html_entity_decode($xml_output); It may or may not work.. Oh good god. You are my new hero Yay! Thanks, Josh Quote Link to comment Share on other sites More sharing options...
Dragen Posted September 11, 2007 Share Posted September 11, 2007 hehe.. It's because you were outputting it like this: htmlentities($row['TITLE']) Which I guess make it impossible for users to add html such as <b> or <i>, but it does mean that thai or some other languages wont be displayed properly. Quote Link to comment Share on other sites More sharing options...
rhamej Posted September 11, 2007 Author Share Posted September 11, 2007 Ya, I don't want the user to add html. Im trying to make it as idiot proof as possible Thanks again Dragen Quote Link to comment Share on other sites More sharing options...
Dragen Posted September 11, 2007 Share Posted September 11, 2007 wait.. if you're not wanting to allow html, then you shouldn't use html_entity_decode() as it will turn all of the html back into working html. It won't just display the thai, it will also allow people to use other things such as <b> and <i> Not sure if there's a way round this though.. Quote Link to comment Share on other sites More sharing options...
rhamej Posted September 11, 2007 Author Share Posted September 11, 2007 wait.. if you're not wanting to allow html, then you shouldn't use html_entity_decode() as it will turn all of the html back into working html. It won't just display the thai, it will also allow people to use other things such as <b> and <i> Not sure if there's a way round this though.. Umm, I think you got it right the first time? I don't want the user to be able to add tags. ??? Quote Link to comment Share on other sites More sharing options...
Dragen Posted September 11, 2007 Share Posted September 11, 2007 keep the code as it is and try putting some html tags into the text. See if it allows the html or not. Quote Link to comment Share on other sites More sharing options...
rhamej Posted September 11, 2007 Author Share Posted September 11, 2007 Ya, it allows them, and I can always have Flash read the text as html text to format the font. http://2210media.com/test2/xml.php But as I said, they won't be adding tags anyway Quote Link to comment 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.