Updating xml file using c ccamelia dating
Hope it might help somebody and would be very interested to hear of better solutions. ;)It looks for any Occasionally you may try to load a file and have it complain about an entity and throw a parser error.
I bashed together this little regex function to sort out the CDATA before trying to parse XML with the likes of simplexml_load_file / simplexml_load_string.
The data coming from simplexml are Objects and the bind parameters functions of My SQLi do NOT like that!
(it causes some memory leak and can crash Apache/PHP)In order to do this properly you MUST cast your values to the right type (string, integer...) before passing them to the binding methods of My SQLi.
If it does, or if you want to err on the side of caution, then instead of using simplexml_load_file, try this:$file = file_get_contents('stuff.xml');$temp = preg_replace('/&(?!
(quot|amp|pos|lt|gt);)/', '&', $file);$xml = simplexml_load_string($temp) or die("xml not loading"); Read the file into a string, add 'amp;' after any '&' that is not part of a character entity, then parse the string as xml.