Strip Illegal XML Characters from a UTF-8 String


/ Published in: PHP
Save to your folder(s)

Some valid UTF-8 characters are illegal in XML:
http://www.w3.org/TR/REC-xml/#charsets

This statement strips them from your strings.


Copy this code and paste it in your HTML
  1. preg_replace('/[^\\x0009\\x000A\\x000D\\x0020-\\xD7FF\\xE000-\\xFFFD]/', ' ', $string);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.