[PHP] SimpleXML - issue with getting data out of the object returned
Hi, I have a basic XML document that I am grabbing with simplexml_load_string(), here is the print_r: SimpleXMLElement Object ( [Package] => SimpleXMLElement Object ( [PackageID] => 804 [PackageName] => Silver [BandwidthGB] => 20 [WebStorageMB] => 5120 [DBStorageMB] => 250 [POPMailBoxes] => 50 [WebStorageUnits] => 5 [BandwidthUnits] => 1 [DBStorageUnits] => 1 [POPUnits] => 5 [DomainHeaders] => 50 [DBType] => MSSQL [OSType] => Windows [Enabled] => True ) [Count] => 1 ) When I try and access $x->Package->PackageID I don't get 804, I get: SimpleXMLElement Object ( [0] => 804 ) Could someone tell me how I just get the value 804 out of there? -- -Dan Joseph www.canishosting.com - Plans start @ $1.99/month. "Build a man a fire, and he will be warm for the rest of the day. Light a man on fire, and will be warm for the rest of his life."
Re: [PHP] SimpleXML - issue with getting data out of the object returned
Tim-Hinnerk Heuer http://www.ihostnz.com On Fri, Dec 19, 2008 at 3:50 PM, Dan Joseph wrote: > Hi, > > I have a basic XML document that I am grabbing with > simplexml_load_string(), > here is the print_r: > > SimpleXMLElement Object > ( >[Package] => SimpleXMLElement Object >( >[PackageID] => 804 >[PackageName] => Silver >[BandwidthGB] => 20 >[WebStorageMB] => 5120 >[DBStorageMB] => 250 >[POPMailBoxes] => 50 >[WebStorageUnits] => 5 >[BandwidthUnits] => 1 >[DBStorageUnits] => 1 >[POPUnits] => 5 >[DomainHeaders] => 50 >[DBType] => MSSQL >[OSType] => Windows >[Enabled] => True >) > >[Count] => 1 > ) > > When I try and access $x->Package->PackageID I don't get 804, I get: > > SimpleXMLElement Object >( >[0] => 804 >) > Had that problem before: $val = (string) $x->Package->PackageID; or $val = (int) $x->Package->PackageID; or whatever type you want. ;) > > Could someone tell me how I just get the value 804 out of there? > > -- > -Dan Joseph > > www.canishosting.com - Plans start @ $1.99/month. > > "Build a man a fire, and he will be warm for the rest of the day. > Light a man on fire, and will be warm for the rest of his life." >
Re: [PHP] SimpleXML - issue with getting data out of the object returned
On Thu, Dec 18, 2008 at 10:01 PM, German Geek wrote: > $val = (string) $x->Package->PackageID; > or > $val = (int) $x->Package->PackageID; > > Ha... I would have never figured that out... Thank you to you both! That did the trick. -- -Dan Joseph www.canishosting.com - Plans start @ $1.99/month. "Build a man a fire, and he will be warm for the rest of the day. Light a man on fire, and will be warm for the rest of his life."