simplexml_load_string - Exception => Entity: line 1: parser error : Start tag expected, '<' not found

13,215

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:

Share:
13,215
Ramin Omrani
Author by

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, 2022

Comments

  • Ramin Omrani
    Ramin Omrani over 1 year

    I'm trying to parse a GuzzleHTTP\PSR7\Response into a SimpleXMLElement Object using simplexml_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());