# XML Data into an array

**URL:** <https://forum.kirupa.com/t/xml-data-into-an-array/237696>\
**Category:** Uncategorized\
**Created:** [September 2, 2007, 7:46pm UTC](https://forum.kirupa.com/t/xml-data-into-an-array/237696 "2007-09-02T19:46:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![WearDark](https://avatars.discourse-cdn.com/v4/letter/w/48db29/32.png) [@WearDark](https://forum.kirupa.com/u/WearDark)\
**Post date:** [September 2, 2007, 7:46pm UTC](https://forum.kirupa.com/t/xml-data-into-an-array/237696/1 "2007-09-02T19:46:53Z")

</div>

Using Jubba’s tutorial I’ve manged to parse an xml file with php… my problem now is getting the values into an array… look at this:

```auto

<?php
    $file = "xmlTestFile.xml";

    $arr = array();

    function contents($parser, $data){
        array_push($arr, $data);
    }

    function startTag($parser, $data){
            
    }

    function endTag($parser, $data){
            
    } 
    
    $xml_parser = xml_parser_create();
    xml_set_element_handler($xml_parser, "startTag", "endTag");
    xml_set_character_data_handler($xml_parser, "contents");

    $fp = fopen($file, "r");
    $data = fread($fp, 80000);

    if(!(xml_parse($xml_parser, $data, feof($fp)))){
            die("Error on line " . xml_get_current_line_number($xml_parser));
    }

    echo "COUNT: ";
    echo count($arr);
    xml_parser_free($xml_parser);

    fclose($fp); 

?>

```

So when the parser finds content it should add the value to the array right? Or am I missing something here?

Cheers.
