mpman Posted December 5, 2008 Share Posted December 5, 2008 $xmlFileData = file_get_contents("xml/myxml.xml"); $xmlData = new SimpleXMLElement($xmlFileData); $xmlName = $xmlData->color[0]->name; -------------------------------------------------- Hi all, using the method above i manage to call text from a specific node. But.. what if i want to have the nodes to be called dynamically like this: $xmlName = $xmlData->color[$dynamic number]->name; So i can use only 1 template page. I tried having the number called from the URL: $xmlName = $xmlData->property[print $_GET[myID]]->name; I also tried echoing etc. however it seems like it just can't work. Here is the output: 0red If i choose "1" like myID=1, the output is: 1red The array number seem to stay as default... Is there a way to have the array'[]' get the number and use it as [1] or [2] based on the URL? basically having the number inside the [] change.. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/135651-solved-xml-parsing-problem/ Share on other sites More sharing options...
premiso Posted December 5, 2008 Share Posted December 5, 2008 $xmlFileData = file_get_contents("xml/myxml.xml"); $xmlData = new SimpleXMLElement($xmlFileData); $xmlName = $xmlData->color[$_GET['myid']]->name; I think you were just using the $_GET call wrong, you do not have to print it if you are using it internally to PHP. Quote Link to comment https://forums.phpfreaks.com/topic/135651-solved-xml-parsing-problem/#findComment-706753 Share on other sites More sharing options...
mpman Posted December 5, 2008 Author Share Posted December 5, 2008 I did try that already and it does nothing, its almost as if the data cannot be called into the [] If i use a regular variable such $myVar=0 it works i think that i need to turn the URL value into a numeric value rather than a string... [$myVar] does work. Quote Link to comment https://forums.phpfreaks.com/topic/135651-solved-xml-parsing-problem/#findComment-706762 Share on other sites More sharing options...
premiso Posted December 5, 2008 Share Posted December 5, 2008 Are you sure you are passing in a get variable? $myid = isset($_GET['myid'])?$_GET['myid']:0; // if $_GET is not present assign the value default of 0 $xmlFileData = file_get_contents("xml/myxml.xml"); $xmlData = new SimpleXMLElement($xmlFileData); $xmlName = $xmlData->color[$myid]->name; Just an fyi, it is possible to access elements of the array using an array identifier, so the previous should work as long as "myid" was set using the get such as: http://www.mysite.com/xml.php?myid=1 Chances are the above will not work if you have not been calling the page like that. Quote Link to comment https://forums.phpfreaks.com/topic/135651-solved-xml-parsing-problem/#findComment-706766 Share on other sites More sharing options...
mpman Posted December 5, 2008 Author Share Posted December 5, 2008 SOLVED!! $xmlName = $xmlData->property[intval($myVar)]->name; Page already calls it like this, thanks bro. Quote Link to comment https://forums.phpfreaks.com/topic/135651-solved-xml-parsing-problem/#findComment-706768 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.