Last active
August 29, 2015 14:27
-
-
Save ederrafo/07be39b273616e47fae7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$xml_string = ' | |
<getHotelAvailRequest> | |
<destination>130336</destination> | |
<checkin>14-02-2015</checkin> | |
<checkout>16-02-2015</checkout> | |
<nationality>136</nationality> | |
<listrooms> | |
<item> | |
<count>2</count> | |
<adults>1</adults> | |
<children>1</children> | |
<childrenages> | |
<item><age>1</age> | |
</item> | |
</childrenages> | |
</item> | |
<item> | |
<count>1</count> | |
<adults>2</adults> | |
<children>1</children> | |
<childrenages> | |
<item><age>1</age></item> | |
</childrenages> | |
</item> | |
</listrooms> | |
<language>en</language> | |
</getHotelAvailRequest> | |
'; | |
/* | |
ENT_QUOTES - Encodes double and single quotes | |
*/ | |
echo "FILE: ",__FILE__,"<br>LINE: ", __LINE__,"<pre>", htmlspecialchars($xmlString, ENT_QUOTES); echo "</pre>"; | |
/* Convert XML string to SimpleXMLElement Object */ | |
$simple_xml_object = simplexml_load_string($xml_string); | |
echo "FILE: ",__FILE__,"<br>LINE: ", __LINE__,"<pre>"; print_r($simple_xml_object); echo "</pre>"; | |
/* Convert to json string*/ | |
$json = json_encode($simple_xml_object); | |
echo "FILE: ",__FILE__,"<br>LINE: ", __LINE__,"<pre>"; print_r($json); echo "</pre>"; | |
/* | |
Convert to array. | |
TRUE: delete objects | |
*/ | |
$array = json_decode($json, TRUE); | |
echo "FILE: ",__FILE__,"<br>LINE: ", __LINE__,"<pre>"; print_r($array); echo "</pre>"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment