• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

XML parser

Hi all,
        Can anyone help me about this how do I parse a xml file using php?  for example i need a attribute named "USER" in the xml file.  How do I get this value from an xml and use it in an php file?

Thanks alot to all
  • 2
1 Solution
See: http://www.php.net/manual/en/function.xml-parse-into-struct.php
In the comments there are a lot of examples how to do this or how to get a strcuture wich can be searched /accessed easyer
KaiwapAuthor Commented:
I am sorry but i m not very good in this script.
for example i have
<?xml version = "1.0" encoding="Windows-874" ?>


if i only want the values in the filename and contents and show it on the other page
Can you give me a sample of how it is done?  
Have a look at this example:


$data = '<?xml version = "1.0" encoding="Windows-874" ?>

$xml_parser = xml_parser_create();
xml_parse_into_struct($xml_parser, $data, $vals, $index);
$result = array();
foreach($index['FILENAME'] as $num => $id) {
    $result[] = array(
        'filename' => $vals[$id]['value'],
        'content'  => $vals[$index['CONTENT'][$num]]['value'],

// for debugging/understanding the structures:

$result will contain:
    [0] => Array
            [filename] => picture.jpg
            [content] => albkja;dlkjoasdihfashdf;kj;eifjo;eijf

    [1] => Array
            [filename] => picture2.jpg
            [content] => albkja;dlkjoasdihfassdfdshdf;kj;eifjo;eijf


This will only work correctly if you have the same count of fielname and contents tag and if the are in the same xml-level.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now