English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP simplexml_load_string() Function Usage and Example

PHP SimpleXML Function Manual

The simplexml_load_string() function is used to convert a formatted XML string to a SimpleXMLElement object.

Syntax

simplexml_load_string(data,classname,options,ns,is_prefix);

Definition and Usage

It is used to convert a formatted xml string to a SimpleXMLElement object.

Return Value

Returns a SimpleXMLElement object on success, and returns false on failure

Parameter

NumberParameters 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.

Online Example

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

PHP SimpleXML Function Manual