0

I have an XML File for an API. The API responses everytime "Errormesage: Expected argument of type "string", "array" given".

$SimpleXML_loaded_File = simplexml_load_file("http://graphics.edc-internet.nl/b2b_feed.php?key=tc62te28wt3e2t73ctr9c1cw42601337&sort=xml&type=xml&lang=de"); foreach ($SimpleXML_loaded_File->product as $product) { /*$client->post('articles', array( 'name' => $product->titel, 'taxId' => 1, 'supplier' => $product->merk, 'mainDetail' => array( 'number' => $product->artikelnummer ) ));*/ echo "<pre>"; var_dump($product->artikelnummer); echo "</pre>"; } 

If i var_dump the Output i dont get a string i`m getting the object

object(SimpleXMLElement)#6 (1) { [0]=> string(7) "0633178" } 

How do i get only the string ?

1
  • var_dump() is not asking for a string value specifically, so you might just have chosen the wrong function. You might haven been looking for strval() instead. Or many of the other string functions in PHP. Commented Mar 6, 2015 at 22:44

2 Answers 2

2

SimpleXML is simple for a reason. When echoing an element, it automatically converts the object to a string. You can also explicitly cast it to one:

echo (string)$product->artikelnummer; 
Sign up to request clarification or add additional context in comments.

2 Comments

But why do i get the error message:Errormesage: Expected argument of type "string", "array" given. As i said i get the value with $product->artikelnummer; But the API says it`s an array.
@user3633186 You have to cast your number parameter to a string: 'number' => (string)$product->artikelnummer
0

This issue is related to type casting. Please check.

echo (string)$product->artikelnummer; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.