Jump to content

XML Parser using PHP


leewad

Recommended Posts

Hi

Im trying to get the values out of XML but the nodes are same name so i cannot use

$description = GetElementByName($Nodes[$i], "<description>", "</description>");


the XML is:


<description>picture1</description>
<description>picture2</description>
<description>picture3</description>
<description>picture4</description>

How can I get the value in an array?

i.e

$description1= "picture1";
$description2= "picture2";
$description3= "picture3";
$description4= "picture4";

Many thanks in advance



Link to comment
https://forums.phpfreaks.com/topic/29501-xml-parser-using-php/
Share on other sites

GetElementByName() isn't a PHP function that I know of o.o

the EASIEST way that I know of... would be something like this...

[code=php:0]
<?php
$descriptions = <<<EOT
<descriptions>
<description>picture1</description>
<description>picture2</description>
<description>picture3</description>
<description>picture4</description>
</descriptions>
EOT;

$descriptions = simplexml_load_string($descriptions);

foreach ($descriptions->description as $description) {
    echo $description;
}
?>
[/code]


There is no easy way I can think of you being able to loop through the "<description>" elements without having a parent element. (using XML functions that is, it's easy to do it with just manipulating the text with non-XML functions)

Alternatively you could create a pretty big parser for such a little application... for more info on that you could start here... http://www.php.net/xml_parser_create

Sorry I couldn't give you any more info! gl
Link to comment
https://forums.phpfreaks.com/topic/29501-xml-parser-using-php/#findComment-135376
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.