1

The answer to this is probably studpidly simple, but I can't for the life of me figure it out...

Per PHP's documentation, the 2nd parameter for the "SimpleXMLElement::__construct()" method, called "$option", is an integer, defined as: "Optionally used to specify additional Libxml parameters." Please note the plural of "parameters".

I get how to pass a single option, say:

$x = new SimpleXMLElement($feed_url, LIBXML_NOCDATA, TRUE);

But what if, in addition to "LIBXML_NOCDATA", I want to also pass "LIBXML_NOBLANKS", and/or "LIBXML_BIGLINES"? How do I pass those within the same call?

Example:

$x = new SimpleXMLElement($feed_url, LIBXML_NOCDATA LIBXML_NOBLANKS LIBXML_BIGLINES, TRUE);

(BTW, I know this doesn't work...)

What am I missing / not understanding?

Thanks!

  • 1
    Separate with pipe character (bitwise or), e.g. `LIBXML_NOCDATA | LIBXML_NOEMPTYTAG` – marekful Jul 23 '18 at 15:48
  • As a tip, the `LIBXML_NOCDATA` option is pretty pointless with SimpleXML anyway; people use it because they wrongly think it's needed to read CDATA (it's not - see https://stackoverflow.com/questions/16835287/reading-text-in-cdata-with-simplexmlelement/16842431#16842431 and https://stackoverflow.com/questions/3650203/getting-cdata-content-while-parsing-xml-file/13830559#13830559). For what that option actually does, see this answer: https://stackoverflow.com/questions/13979582/php-simplexml-decoding-entities-in-cdata/13981917#13981917 – IMSoP Jul 23 '18 at 15:58

1 Answers1

4

Use a bitwise OR to get the final value.

$x = new SimpleXMLElement($feed_url, LIBXML_NOCDATA | LIBXML_NOBLANKS | LIBXML_BIGLINES, TRUE);
Quentin
  • 857,932
  • 118
  • 1,152
  • 1,264