Sometimes you need to export a collection of data for use to another system. One of the easiest ways is to export it to XML as it is widely accepted as a data exchange format and standard. PHP makes creating and exporting to XML very easy. Below I’ll show you an example where I am exporting… Read More
I had to process a lot of Word .docx files into readable content for use in a searchable database. Docx files are basically xml files in a zipfile container (as described by wikipedia). Here is my solution, it’s pretty straight forward. Just pass in the server file path to the read_docx() function and it will… Read More
When you put UTF-8 encoded strings into an XML document you should remember that not all UTF-8 characters are accepted in an XML document http://www.w3.org/TR/REC-xml/#charsets You should strip away the invalid characters, else you’ll have an XML fatal parsing error tossed during parsing. It’s rather easy to accomplish this using the following function.
1 2 3 4 5 6 7 |
<?php /* Remove all UTF-8 Chars that are not acceptable for usin in an XML payload */ function utf8_for_xml($string) { return preg_replace ('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $string); } ?> |