elg2001 Posted May 10, 2006 Share Posted May 10, 2006 Hi, I've done alot of looking into this. Wikipedia's website sends UTF-8 text and can embed unicode characters in a page (such as a greek delta symbol). However, when I try to accomplish the same thing in PHP, when I submit a delta symbol using a text area and an html form with [b]method="post"[/b], it gets stored in an XML file. Then when I try to view what i have submitted in html, I see [b]Î[/b] where the delta symbol should be. The code to store the <textarea>'s content is as follows:[code]$body = $doc->createElement('body');$bodytext = $doc->createTextNode(utf8_encode(str_replace(' ', ' ', str_replace("\n", '<br />', str_replace("\r", '<br />', str_replace("\r\n", '<br />', htmlentities(stripslashes($_POST['body']))))))));$body->appendChild($bodytext);$post->appendChild($body);$doc->documentElement->insertBefore($post, $doc->documentElement->firstChild);$doc->formatOutput = false;$doc->save($fPath);[/code]I'm using the [b]utf8_encode()[/b] function because without it there, PHP throws an exception that the submitted character is not a valid XML character. The XML file's encoding is UTF-8, declared as follows:[code]$doc = new DOMDocument('1.0', 'UTF-8');[/code]Can anyone steer me in the right direction? Link to comment https://forums.phpfreaks.com/topic/9493-storing-text-in-an-xml-file/ Share on other sites More sharing options...
elg2001 Posted May 11, 2006 Author Share Posted May 11, 2006 and by the way, if I DO use utf8_encode(), it works. however, all non-ascii characters are replaced with junk characters, so I end up with a valid XML document but an invalid XHTML document. Link to comment https://forums.phpfreaks.com/topic/9493-storing-text-in-an-xml-file/#findComment-35126 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.