Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

PHP

Simple XML to associative array (PHP)

1
2
3
4
5
6
// XML to associative array

$xml_string = file_get_contents("php://input");
$xml  = simplexml_load_string($xml_string);
$json = json_encode($xml);
$arr  = json_decode($json, true);
https://snipt.net/embed/722c731c88b4e580fae7f3ebf2c563ba/
https://snipt.net/raw/722c731c88b4e580fae7f3ebf2c563ba/
722c731c88b4e580fae7f3ebf2c563ba
php
PHP
6
2016-12-04T08:31:11
True
False
False
/api/public/snipt/101477/
xml-to-associative-array-php
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="x">// XML to associative array</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="x">$xml_string = file_get_contents(&quot;php://input&quot;);</span> </span><span id="L-4"><a name="L-4"></a><span class="x">$xml = simplexml_load_string($xml_string);</span> </span><span id="L-5"><a name="L-5"></a><span class="x">$json = json_encode($xml);</span> </span><span id="L-6"><a name="L-6"></a><span class="x">$arr = json_decode($json, true);</span> </span></pre></div> </td></tr></table>
array, php, xml
Copyrighted, illegal, or inappropriate content? Email [email protected].