• PHP Video Tutorials

PHP - Function Simplexml Load String



Syntax

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

Definition and Usage

It used to converts formatted xml string into a SimpleXMLElement object.

Return Values

It returns a SimpleXMLElement object on success or false on failure

Parameters

Sr.No Parameters & Description
1

data

It is used to specifies formatted xml string

2

classname

It is used to specifies the class of new object

3

ns

It is used to specifies a namespace prefix or URI

4

is_prefix

It is used to specifies boolean value if result is true than ns is prefix or else gives a result as false

Example

Try out the following example

<?php
   $note = <<<XML
   
   <note>
      <to>Gopal</to>
      <from>CEO</from>
      <heading>Reminder</heading>
      <body>Don't forget to send a file to me</body>
   </note>
   XML;
   
   $xml = simplexml_load_string($note);
   echo $xml->to . "<br>";
   echo $xml->from . "<br>";
   echo $xml->heading . "<br>";
   echo $xml->body;
?>

This will produce following result −

Gopal
CEO
Reminder
Don't forget to send a file to me
php_function_reference.htm
Advertisements