$xml = simplexml_load_file("odds.xml"); $players = $xml->pool.$number->players
Arguments in XML hierarchy
- FrederickGeek8
- Posts: 148
- Joined: Wed Nov 30, 2011 10:31 pm
Arguments in XML hierarchy
OK so I want to do something like this in my PHP code, except I don't think its supported... How would I be able to do this?
Re: Arguments in XML hierarchy
Not really sure what that sample is meant to be doing Could you post some sample data and expected result ?
- FrederickGeek8
- Posts: 148
- Joined: Wed Nov 30, 2011 10:31 pm
Re: Arguments in XML hierarchy
Ok I don't really want to disclose any real code but I'll give an example...
Here is a xml file
Here is a xml file
<?xml ?> <pools> <pool1> <swimmers>10</swimmers> </pool1> <pool2> <swimmers>15</swimmers> </pool2> </pools>And so I can parse it as so
$xml = simplexml_load_file("pools.xml"); $players = $xml->pool1->swimmers; echo $players;but I want to place it in a function as so
<?php function get_swimmers($pool){ $xml = simplexml_load_file("pools.xml"); $players = $xml->pool.$pool->swimmers; echo $players; } ?>but that doesn't really work...
Re: Arguments in XML hierarchy
Ah you need to need to know the element name dynamically.
I believe you can do that like this
I believe you can do that like this
$players = $xml->{"pool{$pool}"}->swimmers;