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> — <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"> = "SimpleXMLElement"</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"><?php<br />$string </span><span style="color: #007700">= <<<XML<br /></span><span style="color: #DD0000"><?xml version='1.0'?> <br /><document><br /> <title>Forty What?</title><br /> <from>Joe</from><br /> <to>Jane</to><br /> <body><br /> I know that's the answer -- but what's the question?<br /> </body><br /></document><br /></span><span style="color: #007700">XML;<br /><br /></span><span style="color: #0000BB">$xml </span><span style="color: #007700">= </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">?></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] => Forty What?
[from] => Joe
[to] => Jane
[body] =>
I know that's the answer -- but what's the question?
)
</pre></div>
</div>
<div class="example-contents simpara"><p>
At this point, you can go about using <i>$xml->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(); ?>