Jump to content

Storing <textarea> text in an XML file


elg2001

Recommended Posts

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('  ', '&nbsp;&nbsp;', 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
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.