1

I have an XML with product. I have a problem with read values witch has a "-" in name because this method dosent work:

$productHurtoID = $product->kod-kreskowy->__toString();

Below You have $product variable:

SimpleXMLElement object {
  nazwa => SimpleXMLElement object
  kod-katalogowy => (string) K0428
  kod-kreskowy => (string) 0027084373370
}

Thanks for help. Kind regards

2 Answers2

1

You could access your dynamically created properties via

$productHurtoID = $product->{'kod-kreskowy'}->__toString();

A different approach would be to pre-process your XML input and replace hyphens with camelCase. But depending on your use-case, this might not be possible.

Regards

0

You can use following code for getting values with - (hyphen) in key.

$productHurtoID = $product->nazwa->{'kod-kreskowy'}->__toString();