devWhiz Posted May 14, 2011 Share Posted May 14, 2011 So I want to be able to make a function that will will parse the XML from my string every time it is called, so say I have this $Result = file_get_contents('http://www.example.com'); Which loads this <outer> <xml> <viewer> <user> <name>bradley</name> <age>18</age> <location>ohio</location> </user> </viewer> </xml> </outer> I parse it with $xml = simplexml_load_string($Result); foreach($xml->xml->viewer->user as $xml2) { $name = $xml2->name; $age = $xml2->age; $location = $xml2->location; } Is there a way possible maybe a function that will be able to allow me to do something like this <?php $Result = file_get_contents('http://www.example.com'); xml_parse($Result); echo $name; $AnotherResult = file_get_contents('http://www.example.com'); xml_parse($AnotherResult); echo $name; ?> Is it possible for me to make a function that stores the xml parse information and it uses it every time it is called on the string that is in the "( )" I am completely illiterate to making functions so every bit of help I can receive is appreciated Thanks Quote Link to comment https://forums.phpfreaks.com/topic/236373-function-help/ Share on other sites More sharing options...
trq Posted May 14, 2011 Share Posted May 14, 2011 http://php.net/functions Quote Link to comment https://forums.phpfreaks.com/topic/236373-function-help/#findComment-1215256 Share on other sites More sharing options...
devWhiz Posted May 14, 2011 Author Share Posted May 14, 2011 Do you know if it is possible or not thorpe? Quote Link to comment https://forums.phpfreaks.com/topic/236373-function-help/#findComment-1215262 Share on other sites More sharing options...
wildteen88 Posted May 14, 2011 Share Posted May 14, 2011 Yes it is possible. Have a go yourself what you're trying to do is pretty basic. Quote Link to comment https://forums.phpfreaks.com/topic/236373-function-help/#findComment-1215303 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.