Jump to content

reading an xml file and parsing into variables


MidOhioIT

Recommended Posts

Is there a way in php to read the following xml file and only parse out the string between the tags <image></image> as example and store in 3 variables. 

examples:

$image1 = <image>http://www.buck.com/slideshow_images/sidesponsor1.jpg</image> (just inside the tags)

$image2 = <image>http://www.buck.com/slideshow_images/sidesponsor2.jpg</image> (just inside the tags)

$image3 = <image>http://www.buck.com/slideshow_images/sidesponsor3.jpg</image> (just inside the tags)

 

 

<?xml version="1.0" encoding="utf-8" standalone="yes"?>

<images>

    <pic>

        <image>http://www.buck.com/slideshow_images/sidesponsor1.jpg</image>

        <caption></caption>

        <link>http://www.wades.com</link>

    </pic>

    <pic>

        <image>http://www.buck.com/slideshow_images/sidesponsor2.jpg</image>

        <caption></caption>

        <link>http://www.facebook.com/pages/Bucom/164093073538?ref=ts</link>

    </pic>

    <pic>

        <image>http://www.buck.com/slideshow_images/sidesponsor3.jpg</image>

        <caption></caption>

        <link>http://www.carnohio.com/</link>

    </pic>

</images>

thank you for the help.  There was a few minor typos but you put me on the right track.  I am only posting this code and making that statement because I am marking this as resolved and the next person to read this can have the actual code that worked with no syntax or flaws.  Thanks again

 

$xmlfile = 'image_and_link.xml';
$xml = simplexml_load_file($xmlfile);
$images = array();
foreach($xml->pic as $link)
{
  $images[] = $link->image;
  $links[] = $link->link;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.