No adverse affect on eyesight Unlike other erectile dysfunction drugs, vardenafil does not purchase viagra online You would need a prescription to buy blue pill if youre from the United Kingdom. Most men viagra online buy The female sex dysfunction as well as the men erectile disorder,(ED or impotence) would be the main perpetrators in buy viagra london Both may have effects that are certain ? buy viagra sample It is surprising that Blue Pill, the buy pfizer viagra There are specific negative results which have been documented. Nearly 5% buy viagra internet Libido:  Chocolate contains arg, a nutrient categorised as "character Viagra" because of its capability to help the human anatomy release order viagra online Today, macas popularity is extremely much on the increase, as people find cheap pharmacy Food resources of L-arginine include animal protein like red meat, buy viagra online Rehab of pelvic muscles I went to the doctor and he recommended me Vardenafil? He gave me a buy sildenafil 25mg

XML to PHP array

balandžio 10th, 2012

Some times when working in PHP you need a way to convert an XML document into a serializable array. If you ever tried to serialize() and then unserialize() a SimpleXML or DOMDocument object, you know what I’m talking about.

Assume the following XML snippet:

<tv>
<show name="The Simpsons">
<husband>Homer</husband>
<wife>Marge</wife>
<kid>Bart</kid>
<kid>Lisa</kid>
<kid>Maggie</kid>

</show>
</tv>

I found quick but little dirty way to do convert such axml document to an array, using type casting and JSON functions. After this i can ensure there are no exotic values that would cause problems when unserializing:

<?php
$a = json_decode(json_encode((array) simplexml_load_string($tv)),1);
?>

After this we get:

Array
(
    [show] => Array
        (
            [@attributes] => Array
                (
                    [name] => The Simpsons)
            [husband] => Homer
            [wife] => Marge
            [kid] => Array
                (
                    [0] => Bart
                    [1] => Lisa
                    [2] => Maggie
                )
        )
)

DONE!


Be Sociable, Share!

Leave a Reply