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>

Link to comment
Share on other sites

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;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.