The little known PHP htmlspecialchars
Want to replace only xml entities <, >, &? Don’t use htmlentites or str_replace; use htmlspecialchars.
The only named entities for XML are &, > and <. For all others you need to use the Unicode character code (eg.  ).
Webkit: Entity ‘nbsp’ not defined – Convert HTML entities to XML