php simplexmlelement - I can access most properties (except the one with a dash?)
Posted
by Matthew Steiner
on Stack Overflow
See other posts from Stack Overflow
or by Matthew Steiner
Published on 2010-06-18T02:37:53Z
Indexed on
2010/06/18
2:43 UTC
Read the original article
Hit count: 303
php
|simplexmlelement
So I run some code like this:
$quote = simplexml_load_string($xml);
$quote = $quote->Stock;
echo 'Name: ';
echo $quote->Name;
echo '<br>';
echo 'Sybmol: ';
echo $quote->Symbol;
echo '<br>';
echo 'Last Price: ';
echo $quote->Last;
echo '<br>';
echo 'Earnings To Price Ratio: ';
echo $quote->P-E;
echo '<br>';
I know that the second to last line ($quote->P-E) is incorrect - I don't think you can use dashes like that. But for some reason I can't figure out how to access that property. The weird thing is that's how it's written if I var_dump($quote) (It's towards the end):
object(SimpleXMLElement)#17 (16) { ["Symbol"]=> string(4) "AAPL" ["Last"]=> string(6) "271.87" ["Date"]=> string(9) "6/17/2010" ["Time"]=> string(6) "3:59pm" ["Change"]=> string(5) "+4.62" ["Open"]=> string(6) "270.72" ["High"]=> string(6) "272.90" ["Low"]=> string(6) "269.50" ["Volume"]=> string(8) "31195032" ["MktCap"]=> string(6) "247.4B" ["PreviousClose"]=> string(6) "267.25" ["PercentageChange"]=> string(6) "+1.73%" ["AnnRange"]=> string(15) "132.88 - 272.90" ["Earns"]=> string(6) "11.796" ["P-E"]=> string(5) "22.66" ["Name"]=> string(10) "Apple Inc." }
How should I be accessing this attribute/property?
© Stack Overflow or respective owner