krackoder
krackoder

Reputation: 2981

Getting values of XML tags with special characters and keywords in PHP

I have a tag in an XML file as "trans-date"

I have loaded the XML file using simpleXML in PHP as

$xml = simplexml_load_file('studentdb.xml');

Now I want to retrieve the value if trans-date field. I have written the code as:

$tdate=$xml->trans-date;

But this line of code is not returning the expected value because "-" is being considered as a minus operator and date as a keyword;

I tried using:

$tdate=$xml->trans."-date";

But this is not working as well. How do I get the value of that field?

Upvotes: 0

Views: 110

Answers (1)

speccode
speccode

Reputation: 1562

Try this:

$tdate=$xml->{'trans-date'};

Upvotes: 1

Related Questions