note 117566 added to function.simplexml-load-file

From: Date: Tue, 30 Jun 2015 13:25:13 +0000
Subject: note 117566 added to function.simplexml-load-file
Groups: php.notes 
Request: Send a blank email to php-notes+get-202997@lists.php.net to get a copy of this message
Occasionally you may try to load a file and have it complain about an entity and throw a parser error. If this is the case, check to make sure that the file in question does not contain an ampersand (&) without a corresponding entity reference. 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. ---- Server IP: 72.52.91.14 Probable Submitter: 96.233.109.34 ---- Manual Page -- http://php.net/manual/en/function.simplexml-load-file.php Edit -- https://master.php.net/note/edit/117566 Del: integrated -- https://master.php.net/note/delete/117566/integrated Del: useless -- https://master.php.net/note/delete/117566/useless Del: bad code -- https://master.php.net/note/delete/117566/bad+code Del: spam -- https://master.php.net/note/delete/117566/spam Del: non-english -- https://master.php.net/note/delete/117566/non-english Del: in docs -- https://master.php.net/note/delete/117566/in+docs Del: other reasons-- https://master.php.net/note/delete/117566 Reject -- https://master.php.net/note/reject/117566 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#202997) next »