simplexml_load_string - Exception => Entity: line 1: parser error : Start tag expected, '<' not found
The function simplexml_load_string
requires a string as it's first parameter that contains well-formed XML. If you do not provide such a string, don't expect the function to work.
In that case, handle the error case and you're fine: The function will return false
if the string couldn't be parsed as XML. The PHP-manual has a whole page about that topic alone:
We should also have Q&A material here on site, for example:
- simplexml error handling php (Aug 2009)
- How to shut up simpleXML on malformed data? (Nov 2009)
Ramin Omrani
I am a software developer based in Rome, Italy, with a particular focus on the web. I became passionate about programming at the age of 14 when I was a member of the Robocup students' team of Tehran. Since then, my passion for learning new tools and trends in programming has never stopped.
Updated on July 28, 2022Comments
-
Ramin Omrani over 1 year
I'm trying to parse a
GuzzleHTTP\PSR7\Response
into aSimpleXMLElement
Object usingsimplexml_load_string()
function. What I'm facing here is I get Randomly Exception that says :Entity: line 1: parser error : Start tag expected, '<' not found
and by randomly I mean once I pass successfully, once fail.
What is your suggestion for
simplexml_load_string()
input/ How to fix the Exception?PHP :
$xml = simplexml_load_string((string)$response->getBody());