Reputation: 2644
Some special characters inside a XML stream may break it. I need to sanitize the data i want to insert in such a stream so that 1) it doesn't corrupt 2) printable UTF-8 characters in it keeps working.
I also need to flush the output out as soon as i generate it, else i would have to keep a lot of stuff in ram.
As of now, i do something like
$return = preg_replace('/[^\p{L}\s]/u', '', $return);
It removes most of not printable characters, but not all of them. I'm having my hard times trying to figure out what characters are causing this problem, however the terminal returns "1;2c " when i encounter one of them.
Do you have any better way to strip out all of these ugly characters?
Upvotes: 1
Views: 771
Reputation: 836
Not sure that you're on the right path ...
1.) Why do you want to transport non-printable (binary?) data in a text-based format?
2.) Check if CDATA helps
<node><![CDATA[ugly characters]]></node>
3.) convert binary data into printable characters using base64
<node><?php echo base64_encode($uglyCharacters); ?></node>
Upvotes: 2