Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

e-mail as object name

Tags:

php

I have a XML with a node called 'e-mail'. I use simplexml_load_file to read the file but when i want to get the row value with $row->e-mail i get just get 0 back.

What's wrong here, all other names work fine so i think it has something to do with 'mail'.

tnx

like image 908
dazz Avatar asked Dec 13 '25 18:12

dazz


2 Answers

From the manual

Accessing elements within an XML document that contain characters not permitted under PHP's naming convention (e.g. the hyphen) can be accomplished by encapsulating the element name within braces and the apostrophe.

echo $xml->movie->{'great-lines'}->line;

So you need something like

$row->{'e-mail'}
like image 148
Paul Dixon Avatar answered Dec 15 '25 08:12

Paul Dixon


This should work:

$row->{'e-mail'}
like image 30
Mischa Avatar answered Dec 15 '25 09:12

Mischa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!