I have a form where I'm trying to ensure I'm handling special characters. One of the fields in the form is Title, defined in the form as input type='text'. The value entered into it as a test is something like (Ann & Andy's First "Test" Pic). For clarity, the entered text is only what is inside the brackets, and does not include the brackets.
I post the Title into a variable as follows:
if (isset($_POST["submitupdate"])) {
$form_title = htmlspecialchars($_POST["title"], ENT_QUOTES, 'UTF-8');
}
At the end of the process I write the value in $form_title to an XML node:
$xml = simplexml_load_file('mydata.xml');
$sxe = new SimpleXMLElement($xml->asXML());
$newparent = $sxe->addChild("Book");
$newparent->addChild("Title", $form_title);
$sxe->asXML('mydata.xml');
I check the XML file to find the text in the file appears as Ann & Andy's First "Test" Pic
rather than what I expect to get, which should be Ann & Andy$apos;s First "Test" Pic
.
To answer the most obvious question, I am using ENT_QUOTES, not ENT_NOQUOTES. To make sure I wasn't losing my mind, I tried it both ways and got the exact same result either way.
I can't for the life of me make any sense of this. Any ideas?
Title and Question updated on suggestion of deceze.