downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/function.simplexml-load-string.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/ref.simplexml.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'function.simplexml-load-string.php',
   
1 => 'simplexml_load_string',
  ),
 
'up' =>
  array (
   
0 => 'ref.simplexml.php',
   
1 => 'SimpleXML Functions',
  ),
 
'prev' =>
  array (
   
0 => 'function.simplexml-load-file.php',
   
1 => 'simplexml_load_file',
  ),
 
'next' =>
  array (
   
0 => 'book.wddx.php',
   
1 => 'WDDX',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="function.simplexml-load-string" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">simplexml_load_string</h1>
  <p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">simplexml_load_string</span> &mdash; <span class="dc-title">
   Interprets a string of XML into an object
  </span></p>

 </div>
 <a name="function.simplexml-load-string.description"></a><div class="refsect1 description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">object</span> <span class="methodname"><b>simplexml_load_string</b></span>
    ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$data</tt></span>
   [, <span class="methodparam"><span class="type">string</span> <tt class="parameter">$class_name</tt><span class="initializer"> = &quot;SimpleXMLElement&quot;</span></span>
   [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$options</tt><span class="initializer"> = 0</span></span>
   [, <span class="methodparam"><span class="type">string</span> <tt class="parameter">$ns</tt></span>
   [, <span class="methodparam"><span class="type">bool</span> <tt class="parameter">$is_prefix</tt><span class="initializer"> = false</span></span>
  ]]]] )</div>

  <p class="para rdfs-comment">
   Takes a well-formed XML string and returns it as an object.
  </p>
 </div>


 <a name="function.simplexml-load-string.parameters"></a><div class="refsect1 parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   </p><dl>

    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">data</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       A well-formed XML string
      </p>
     </dd>

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">class_name</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       You may use this optional parameter so that
       <b>simplexml_load_string()</b> will return an object of
       the specified class. That class should extend the
       <a href="class.simplexmlelement.php" class="type SimpleXMLElement">SimpleXMLElement</a> class.
      </p>
     </dd>

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">options</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       Since PHP 5.1.0 and Libxml 2.6.0, you may also use the
       <i><tt class="parameter">options</tt></i>
 parameter to specify <a href="libxml.constants.php" class="link">additional Libxml parameters</a>.
      </p>
     </dd>

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">ns</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
      </p>
     </dd>

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">is_prefix</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
      </p>
     </dd>

   
   </dl>
<p>
  </p>
 </div>


 <a name="function.simplexml-load-string.returnvalues"></a><div class="refsect1 returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns an <a href="language.types.object.php" class="type object">object</a> of class <a href="class.simplexmlelement.php" class="type SimpleXMLElement">SimpleXMLElement</a> with
   properties containing the data held within the xml document. On errors, it
   will return <b><tt class="constant">FALSE</tt></b>.
  </p>
 </div>


 <a name="function.simplexml-load-string.errors"></a><div class="refsect1 errors">
  <h3 class="title">Errors/Exceptions</h3>
  <p class="para">
   Produces an <b><tt class="constant">E_WARNING</tt></b> error message for each error
   found in the XML data.
  </p>
  <div class="tip"><b class="tip">Tip</b>
   <p class="para">
    Use <a href="function.libxml-use-internal-errors.php" class="function">libxml_use_internal_errors()</a> to suppress all XML
    errors, and <a href="function.libxml-get-errors.php" class="function">libxml_get_errors()</a> to iterate over them
    afterwards.
   </p>
  </div>
 </div>


 <a name="function.simplexml-load-string.examples"></a><div class="refsect1 examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   </p><div class="example">
    <p><b>Example #1 Interpret an XML string</b></p>
    <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$string&nbsp;</span><span style="color: #007700">=&nbsp;&lt;&lt;&lt;XML<br /></span><span style="color: #DD0000">&lt;?xml&nbsp;version='1.0'?&gt;&nbsp;<br />&lt;document&gt;<br />&nbsp;&lt;title&gt;Forty&nbsp;What?&lt;/title&gt;<br />&nbsp;&lt;from&gt;Joe&lt;/from&gt;<br />&nbsp;&lt;to&gt;Jane&lt;/to&gt;<br />&nbsp;&lt;body&gt;<br />&nbsp;&nbsp;I&nbsp;know&nbsp;that's&nbsp;the&nbsp;answer&nbsp;--&nbsp;but&nbsp;what's&nbsp;the&nbsp;question?<br />&nbsp;&lt;/body&gt;<br />&lt;/document&gt;<br /></span><span style="color: #007700">XML;<br /><br /></span><span style="color: #0000BB">$xml&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">simplexml_load_string</span><span style="color: #007700">(</span><span style="color: #0000BB">$string</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$xml</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents para"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
SimpleXMLElement Object
(
  [title] =&gt; Forty What?
  [from] =&gt; Joe
  [to] =&gt; Jane
  [body] =&gt;
   I know that&#039;s the answer -- but what&#039;s the question?
)
</pre></div>
    </div>
    <div class="example-contents simpara"><p>
     At this point, you can go about using <i>$xml-&gt;body</i>
     and such.
    </p></div>
   </div><p>
  </p>
 </div>


 <a name="function.simplexml-load-string.seealso"></a><div class="refsect1 seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   </p><ul class="simplelist">
    <li class="member"><a href="function.simplexml-load-file.php" class="function" rel="rdfs-seeAlso">simplexml_load_file()</a> - Interprets an XML file into an object</li>
    <li class="member"> <span class="methodname"><a href="simplexmlelement.construct.php" class="function" rel="rdfs-seeAlso">SimpleXMLElement::__construct</a> - Creates a new SimpleXMLElement object</span></li>
    <li class="member"><a href="simplexml.examples-errors.php" class="xref">Dealing with XML errors</a></li>
    <li class="member"><a href="function.libxml-use-internal-errors.php" class="function" rel="rdfs-seeAlso">libxml_use_internal_errors()</a> - Disable libxml errors and allow user to fetch error information as needed</li>
   </ul><p>
  </p>
 </div>

</div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites