Is there any function that I can use to parse any string to ensure that it doesn't cause problems with xml parsing? I have a php script outputting an XML file with content retrieved from forms.
The fact is that, in addition to the usual checks of strings from a php form, part of the user text causes xml parsing errors. I came across this " ’ " in particular. This is the error I get Entity 'rsquo' not defined
Does anyone have any experience coding text for xml output?
Thanks!
Some clarifications: I am outputting content from forms to an XML file, which is subsequently parsed by javascript.
I process all form input: htmlentities(trim($_POST['content']), ENT_QUOTES, 'UTF-8');
When I want to output this content to an xml file, how can I encode it so that it does not cause xml parsing errors?
The following 2 solutions still work:
1) echo '<content><![CDATA['.$content.']]></content>';
2) echo '<content>'.htmlspecialchars(html_entity_decode($content, ENT_QUOTES, 'UTF-8'),ENT_QUOTES, 'UTF-8').'</content>'."\n";
Are these 2 solutions safe? What's better?
Thank you, sorry for not providing this information before.
source share