I have a PHP variable that contains a string which represents an XML structure. This string contains ilegal characters that dont let me build a new SimpleXMLElement object f
trim() will also remove null characters, from either end of the source string (but not within).
$text = trim($text);
I've found this useful for socket server communication, especially when passing JSON around, as a null character causes json_decode() to return null.