【发布时间】:2017-01-31 17:31:36
【问题描述】:
我使用 simplexml_load_string 解析了以下 xml:
<ItemAttributes>
<Binding>Misc.</Binding>
<Brand>Gotcha</Brand>
<Feature>schöne Kontraststickerei</Feature>
<Feature>langer und taillierter Schnitt</Feature>
<Feature>kleine Kängurutasche</Feature>
<Feature>Druckknopfleiste mit großen Metallknöpfen</Feature>
<Feature>Rückseite figurbetonend gerafft</Feature>
<ProductGroup>Sports</ProductGroup>
<ProductTypeName>SPORTING_GOODS</ProductTypeName>
<Title>Gotcha Damen Strickjacke</Title>
</ItemAttributes>
并且想要获取数组键中的所有“功能”。其实我是这样做的:
$response = array(
"details" => htmlentities((string) $item->ItemAttributes->Feature)
);
这样我只获取第一个属性。 “schöne Kontraststickerei”。但我想在 $response['details'] 中包含所有属性。最好用逗号分隔。
【问题讨论】:
-
显示如何加载 xml 内容
-
$response = array(); foreach ($item->children() as $node) { $response[] = $node->Feature; } print_r($response);