English 中文(简体)
从PHP的XML物体获取信息
原标题:Getting information from an XML object in PHP

我正在使用一些XML教区,从APIC、blah blah......获得一些信息。

在我的发言稿中有一个地方,我需要把扼杀变成暗中,但我不敢肯定......

我反对:

object(parserXMLElement)#45 (4) {
  ["name:private"]=>
  string(7) "balance"
  ["data:private"]=>
  object(SimpleXMLElement)#46 (1) {
    [0]=>
    string(12) "11426.46"
  }
  ["children:private"]=>
  NULL
  ["rows:private"]=>
  NULL
}

I need to have this string "11426.46" stored in some var as integer.
When I echo $parsed->result->balance I get that string, but if I want to cast it as int, the result is: 1.

Please help!
Thanks a lot!

最佳回答

you have an object, intval of an object will always be 1(if it doesnt have a __toString() magic method defined). you can intval SimpleXMLElement and it will return 11426, but to do that, the data member of the parserXMLElement class has to be public. you might need to define a getData() method for the parserXMLElement class or make the data member public.

问题回答




相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

How to get instance from string in C#?

Is it possible to get the property of a class from string and then set a value? Example: string s = "label1.text"; string value = "new value"; label1.text = value; <--and some code that makes ...

XML DOM parsing br tag

I need to parse a xml string to obtain the xml DOM, the problem I m facing is with the self closing html tag like <br /> giving me the error of Tag mismatch expected </br>. I m aware this ...

Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

Locating specific string and capturing data following it

I built a site a long time ago and now I want to place the data into a database without copying and pasting the 400+ pages that it has grown to so that I can make the site database driven. My site ...

热门标签