Re: Handling SimpleXMLElements
| From: | Satyam | Date: | Fri, 12 Jan 2007 07:52:47 +0000 |
| Subject: | Re: Handling SimpleXMLElements | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-246975@lists.php.net to get a copy of this message | ||
----- Original Message ----- From: "Jochem Maas" <jochem@iamjochem.com>
I'm guessing you have php5.0.x running - you really want a php5.1.xPhpInfo reports it's 5.2.0 so I'm covered there.
version if your going to use XML - it will avoid *alot* headaches with regarding to using var_dump() (or print_r() or even echo) to figure out what the simpleXML objects are/contain. Satyam wrote:I have a problem trying to handle SimpleXml objects. Though I can manage some workaround the problem, I would like to understand it better.....cell. Function dump() just does a var_dump() of whatever is given in the first argument within a <pre> tag and uses the second argument as a heading, surrounded by dashes. In this case I copied the expression of what I am dumping as the title (within single quotes so it does not expand). foreach($row as $cell) { dump($cell,'$cell); dump($cell->p,'$cell->p'); dump((array)$cell->p,'(array)$cell->p'); dump($cell->p[1],'$cell->p[1]'); } The section in question is shown below. Though $cell is shown as a SimpleXMLElement containing one 'p' property which contains an array of two elements: ----------------------------$cell----------------- object(SimpleXMLElement)#8 (1) { ["p"]=> array(2) { [0]=> string(12) "Indian Rupee" [1]=> string(8) "Ngultrum" } } If I dump that 'p' element, I don't get an array but an object with just one element, the first value in the array ----------------------------$cell->p----------------- object(SimpleXMLElement)#7 (1) { [0]=> string(12) "Indian Rupee" } If I typecast it to an array, I still get a single element ----------------------------(array)$cell->p----------------- array(1) { [0]=> string(12) "Indian Rupee" } Nevertheless, if I explicitly index into the 'p' element, without even typecasting it into an array, the second element is there. ----------------------------$cell->p[1]----------------- object(SimpleXMLElement)#10 (1) { [0]=> string(8) "Ngultrum" } So, now you see it, now you don't, or do you? What's happening? Satyam