0

From which PHP 5 version does simplexml_load_file support CDATA?

 $xml = @simplexml_load_file($url, NULL, LIBXML_NOCDATA);

Thanks!!

Rik de Vos
  • 3,387
  • 5
  • 26
  • 34
  • You're contradicting yourself a little here; you want CDATA support, yet you've set the `LIBXML_NOCDATA` flag? – Bojangles Sep 06 '11 at 19:44
  • 1
    i believe the LIBXML_NOCDATA prevents the cdata from being escaped and left out of the object. see: http://us3.php.net/manual/en/function.simplexml-load-file.php#85484 – gregghz Sep 06 '11 at 19:47
  • The CDATA is not "left out of the object", it is just not visible in `var_dump`, `print_r`, etc, causing confusion. There is no need to pass `LIBXML_NOCDATA` in order to work with SimpleXML in the normal way; for an explanation of what it actually does, see http://stackoverflow.com/a/13981917/157957 – IMSoP May 30 '13 at 17:31

3 Answers3

3

I'm not entirely sure this answers your question (some clarity might help?) but I found this at php.net:

http://us3.php.net/manual/en/function.simplexml-load-file.php#82067

"A PHP version >= 5.1.0 is required for this to work"

gregghz
  • 3,885
  • 6
  • 39
  • 66
  • Does it also support CDATA from that version? – Rik de Vos Sep 06 '11 at 20:00
  • the only thing that is clear to me is that 5.1 is required to include the CDATA in the object. I'm not sure what happens when using php < 5.1. – gregghz Sep 06 '11 at 20:21
  • PHP 5.1 is required to support the `LIBXML_NOCDATA` option; it is **not** required to include the CDATA in the object, becase the CDATA is always there - it's just not visible in `var_dump`, `print_r`, etc – IMSoP May 30 '13 at 18:02
1

As in http://php.net/manual/en/function.simplexml-load-file.php said, I think from PHP version >= 5.1.0

John Skoumbourdis
  • 2,731
  • 21
  • 28
0

SimpleXML supports CDATA in any version, and there is no need to pass LIBXML_NOCDATA. See https://stackoverflow.com/a/13830559/157957 and https://stackoverflow.com/a/16842431/157957

Community
  • 1
  • 1
IMSoP
  • 77,988
  • 8
  • 99
  • 149