Jump to content

PHP XML HELP


tqla

Recommended Posts

I am working with an XML file that is formatted like this:

 

<pictures>
<pix pic="image1.png" alt="Tooltip Text 1" desc="Content 1" />
<pix pic="image2.png" alt="Tooltip Text 2" desc="Content 2" />
</pictures>

 

I need to load the file and make it into an array so that I can get the "pic", "alt" and "desc" information so that I can echo them.

 

I try this but it prints nothing:

 

$xml = simplexml_load_file('file.xml');
print_r($xml);

 

This prints nothing too:

 

$data = file_get_contents('file.xml');
print_r($data);

 

I figure it's because of the format of the xml file but I cannot change that.

 

All help appreciated.

Link to comment
https://forums.phpfreaks.com/topic/264016-php-xml-help/
Share on other sites

It seems to be something about the way the xml is formatted.

 

Your suggestions work great with this:

 

<catalog>
   <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
   </book>
   <book id="bk102">
      <author>Ralls, Kim</author>
      <title>Midnight Rain</title>
   </book>
</catalog>

 

But I cannot get a result with this:

 

<pictures>
<pix pic="image1.png" alt="Tooltip Text 1" desc="Content 1" />
<pix pic="image2.png" alt="Tooltip Text 2" desc="Content 2" />
</pictures>

 

More help appreciated. Thanks.

Link to comment
https://forums.phpfreaks.com/topic/264016-php-xml-help/#findComment-1353030
Share on other sites

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.