Some notes about SimpleXML. SimpleXML provides a simple and fast XML operation method, greatly improving the efficiency of XML operations. But sometimes it may cause a lot of trouble to be careful. look at the following code: $ xmls SimpleXML provides a simple and fast XML operation method, greatly improving the efficiency of XML operations. But sometimes it may cause a lot of trouble if you are not careful. check the following code:
$ Xml = simplexml_load_string ( Title );
$ Title = $ xml-> title;
Echo $ title;
$ Xml-> title = test;
Echo $ title;
Guess what the second output result will be? It is test, not the title in imagination. Why? The reason is as follows:
Echo gettype ($ xml-> title) // object
Echo get_class ($ xml-> title); // SimpleXMLElement
Can you see that $ xml-> title is an instance of the SimpleXMLElement class, not a string. Therefore, $ title actually stores a reference to the SimpleXMLElement class, rather than a copy of the string. To obtain a copy of a string, you can only perform type conversion:
$ Title = (string) $ xml-> title; // Obtain the string
$ Xml-> title = test;
Echo $ title; // output title
SimpleXMLElement should implement an interface similar to _ tostring () (if you are interested, check the PHP source code in "ext/simplexml ), can be expressed in expressions such as echo similar to a string. Note the following points:
$ _ SESSION [test] = $ xml-> title; // Save a SimpleXMLElement variable to the SESSION.
$ _ SESSION [test] = (string) $ xml-> title; // string
$ _ SESSION [test] = strval ($ xml-> title); // This is also true.
Bytes. But sometimes it may cause a lot of trouble if you are not careful about it. See the following code: $ xml = s...