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: 305

Filed under:
|

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

Related posts about php

Related posts about simplexmlelement

  • SimpleXMLElement (PHP) throwing error on XML root attributes

    as seen on Stack Overflow - Search for 'Stack Overflow'
    I am working on a project that will take XML data submitted through a textarea input in a form then extract the data and throw it into a database. I am getting errors about the attribute in the root field of my XML (it is the same schema each time, but with different values). If i remove these attributes… >>> More

  • Parse a json(?) string using php

    as seen on Stack Overflow - Search for 'Stack Overflow'
    I have a string, more specifically, this one: a:16:{s:9:"pseudonym";O:16:"SimpleXMLElement":0:{}s:14:"parallel_title";O:16:"SimpleXMLElement":0:{}s:9:"title_var";O:16:"SimpleXMLElement":0:{}s:6:"series";O:16:"SimpleXMLElement":0:{}s:9:"vol_title";O:16:"SimpleXMLElement":0:{}s:9:"reference";O:16:"SimpleXMLElement":0:{}s:10:"bound_with";O:16:"SimpleXMLElement":0:{}s:15:"general_remarks";O:16:"SimpleXMLElement":0:{}s:6:"copies";O:16:"SimpleXMLElement":1:{i:0;s:1:"1";}s:11:"remarks_BPH";O:16:"SimpleXMLElement":0:{}s:3:"ICN";O:16:"SimpleXMLElement":1:{i:0;s:4:"neen";}s:10:"provenance";O:16:"SimpleXMLElement":0:{}s:7:"binding";O:16:"SimpleXMLElement":0:{}s:10:"size_hxwxd";O:16:"SimpleXMLElement":0:{}s:6:"BookID";O:16:"SimpleXMLElement":1:{i:0;s:4:"6271";}s:5:"repro";O:16:"SimpleXMLElement":0:{}} Is… >>> More

  • Looping through a SimpleXML object, or turning the whole thing into an array.

    as seen on Stack Overflow - Search for 'Stack Overflow'
    I'm trying to work out how to iterate though a returned SimpleXML object. I'm using a toolkit called Tarzan AWS, which connects to Amazon Web Services (SimpleDB, S3, EC2, etc). I'm specifically using SimpleDB. I can put data into the Amazon SimpleDB service, and I can get it back. I just don't know… >>> More

  • I don't get prices with Amazon Product Advertising API

    as seen on Stack Overflow - Search for 'Stack Overflow'
    I try to get prices of an ASIN number with the Amazon Product Advertising API. Code: $artNr = "B003TKSD8E"; $base_url = "http://ecs.amazonaws.de/onca/xml"; $params = array( 'AWSAccessKeyId' => self::API_KEY, 'AssociateTag' => self::API_ASSOCIATE_TAG, 'Version'… >>> More

  • php xml SimpleXMLElement

    as seen on Stack Overflow - Search for 'Stack Overflow'
    <Placemark id="p1"></Placemark> <Placemark id="p2"></Placemark> <Placemark id="p3"></Placemark> <Placemark id="p4"></Placemark> hi,im using SimpleXMLElement in my php, my question is,how do i get placemark id 3? is that something like this ? $xml->Response->Placemark['id=3']->AddressDetails->Country->CountryName; thank… >>> More