我的 xml 看起来像这样:--->
<?xml version="1.0"?>
<childrens>
<child1 entity_id="1" value="Root Catalog" parent_id="0">
<child2 entity_id="2" value="Navigate" parent_id="1">
<child4 entity_id="4" value="Activities" parent_id="2">
</child4>
</child2>
</child1>
</childrens>
我想输出如下内容:--->
根目录
导航
活动
这是我的代码:
<?php
$str = '<childrens>
<child1 entity_id="1" value="Root Catalog" parent_id="0">
<child2 entity_id="2" value="Navigate" parent_id="1">
<child4 entity_id="4" value="Activities" parent_id="2">
</child4>
</child2>
</child1>
</childrens>';
$pattern = '/<(.*)="(.*)">/';
preg_match_all($pattern, $str, $matches);
print_r($matches[1]);
?>