I’ve seen alot of coders implement SimpleXML_load_string() instead of the SimpleXMLElement() class. Are there any benefits to using the former over the latter? I’ve read the PHP manual on simplexml. I couldn’t manage to get a grasp on what it is.
Any help and guidance (perhaps through examples) would be much appreciated. Thanks in advance.
simplexml_load_string()(as the name suggest) load xml from a string and returns an object ofSimepleXMLElement. There is no difference between this and using just the usual constructor of the class.Update:
SimpleXML::__construct()has an additional parameter (the third one)bool $data_is_url = false. If this istruethe behavior is the same assimplexml_load_file()(in conjunction with the common stream wrappers). Thus bothsimplexml_load_*()-functions cover the same functionality asSimpleXML::__construct().Additional the functions
simplexml_load_*()has a second parameterstring $class_name = "SimpleXMLElement"to specify the class of the object to get returned. Thats not a specific feature of the functions, because you can “use” something very similar with usual instanciation tooA difference between the OOP- and the procedural approach is, that the functions return
falseon error, but the constructor throws an Exception.