English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The simplexml_load_string() function is used to convert a formatted XML string to a SimpleXMLElement object.
simplexml_load_string(data,classname,options,ns,is_prefix);
It is used to convert a formatted xml string to a SimpleXMLElement object.
Returns a SimpleXMLElement object on success, and returns false on failure
Number | Parameters and Description |
---|---|
1 | data Specify the formatted xml string |
2 | classname Specify the class of the new object |
3 | ns It is used to specify a namespace prefix or URI |
4 | is_prefix If ns is a prefix, then TRUE; if it is a URI, then FALSE; the default value is FALSE. |
Try the following example, which converts a formatted XML string to a SimpleXMLElement object and then outputs the keys and values of the object
<?php //Convert a formatted XML string to a SimpleXMLElement object and then output the keys and values of the object $note = <<<XML <note> <to>Gopal</to>/to> <from>CEO</from>/from> <heading>Reminder</heading>/heading> Don't forget to send a file to me </note> XML; $xml = simplexml_load_string($note); echo $xml->to . "<br>"; echo $xml->from . "<br>"; echo $xml->heading . "<br>"; echo $xml->body; ?>Test and see‹/›
Output Result
Gopal CEO Reminder Don't forget to send a file to me