PHP and XML. Looping through an XML file with PHP

前端 未结 3 474
情书的邮戳
情书的邮戳 2021-01-14 17:07

I am knee deep in foreach purgatory right now trying to come up with a way to traverse this XML file (actual XML text below) with PHP(following the XML file content.) What I

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-14 18:02

    Recursion could be beneficial to you here.

    children() as $child) {
            foreach($child->attributes() as $attr => $attrVal) {
                print $child;
                if($attrVal == "yes") {
                  display_entities( $child->children() );
                }
            }
        }
    }
    
    $xmlref = simplexml_load_file("gallerylisting.xml");
    
    display_entities($xmlref->children());
    

提交回复
热议问题