0

I have the following xml parsed with simplexml_load_string:

<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>

And want to fetch all "Feature" within on Array key. actually i'm doing like this:

$response = array(
            "details" => htmlentities((string) $item->ItemAttributes->Feature)
);  

With that i only fetch the first attribute. The "schöne Kontraststickerei". but i want to have all attributes in the $response['details']. in best case comma separated.

2
  • show how are loading the xml content Commented Jan 31, 2017 at 17:38
  • $response = array(); foreach ($item->children() as $node) { $response[] = $node->Feature; } print_r($response); Commented Jan 31, 2017 at 17:38

1 Answer 1

1

You can cast each simple XML object to an array:

$response = array(
    "details" => htmlentities((string) implode(",",(array) $item->ItemAttributes->Feature))
); 
Sign up to request clarification or add additional context in comments.

1 Comment

that's it! Thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.