Results 1 to 2 of 2

Thread: xml with php???

  1. #1
    Join Date
    Apr 2006
    Oslo, Norway

    xml with php???

    with the "simplexml_load_file" function i load an xml file into a variable called $staff. and when i use the print_r function on the $staff variable i get this result:

    SimpleXMLElement Object
    [FirstName] => Array
    [0] => James

    [1] => John
    [2] => Wayne
    [3] => Jack
    [4] => Eric
    [5] => Roger


    when i look at the xml data it is styled as this:

    can anyone tell me how i can output this using a foreach loop??

  2. #2
    Join Date
    Jun 2004
    4846′36″ N 910′48″ E
    example, output it as a list:

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
            <style type="text/css">
    # array xml2array(str filename)
    function xml2array($xml_file){
    # loading file
    $xml simplexml_load_file($xml_file);
    # could not load file
    return false;
    # reading values from xml
    foreach($xml->FirstName as $FirstName){
    $xml_array[] = $FirstName;
    # returning array
    return $xml_array;
    $names xml2array("simple-xml.xml");
    $names as $person){

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles