Say you’re trying to create a xml file in PHP by using the SimpleXML library but getting this error:
Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Start tag expected, ‘<' not found in C:\xampp\htdocs\dev\test\sitemapmine.php on line 4
Here’s how that happened and how it can be solved.
SPOT THE DIFFERENCE
$xml = “<?xml version=’1.0′ encoding=’UTF-8′?>”;
$xml = simplexml_load_string($xml);
$xml = “<?xml version=’1.0′ encoding=’UTF-8′?><whatever></whatever>;”;
$xml = simplexml_load_string($xml);
The first block of code will give you the error which tells you that it’s looking for a starting < tag. Introduce a well-formed xml tag at the end of <?xml .... ?> (see code block 2) and the error will go away.
azeem says
following can also be done to resolve this issue:
$sxml = simplexml_load_string(html_entity_decode($xml), ‘SimpleXMLElement’, LIBXML_NOCDATA);
Luis says
$sxml = simplexml_load_string(html_entity_decode($xml), ‘SimpleXMLElement’, LIBXML_NOCDATA);
Solved it!!! THANK YOU @AZEEM.
Andrey says
Thank you!!!
It’s exactly what i was looking for!!!
garry says
Thank you ver much azeem.
You saved a time