ferdynator/PHPWord — pull request #2 by theoboldt (2013-12-03 12:43:40+00:00)
Title: Added new unicode character range of characters which are invalid in xml

We needed to enhance the range of unicode characters which need to be replace up to decimal 31, character U+001F. Exactly this character was written to a file of one of our exports and caused Microsoft Word to be unable to open the exported file. I first expected this character would cause a crash of Word, but I found out that this character is invalid in XML files (http://en.wikipedia.org/wiki/Valid_characters_in_XML) and for this reason it is not possible to open such a XML encoded file with word.
As you can see in the linked document there are even more characters which are not allowed in XML, so I enhanced the htmlspecialchars() used to encode string with a PHP 5.4 feature to return a valid XML string if PHP 5.4 is available.