darkfreaks Posted May 30, 2009 Share Posted May 30, 2009 i have a functiuon that returns XML tags, but the problem is it only returns countrycode and not City. is there something i am doing wrong? <?php if ( $format == 'xml' ) { $xmlObj = simplexml_load_string($response); return $xmlObj->CountryCode; return $xmlObj->City; } ?> Quote Link to comment Share on other sites More sharing options...
jxrd Posted May 30, 2009 Share Posted May 30, 2009 Are you returning two strings from the same function? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted May 30, 2009 Author Share Posted May 30, 2009 yes i am trying to attempt to return City and CountryCode however it only returns Countrycode Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted May 30, 2009 Author Share Posted May 30, 2009 appearantly i cant use return on more than one string or the second return, returns false :-\ Quote Link to comment Share on other sites More sharing options...
jxrd Posted May 30, 2009 Share Posted May 30, 2009 When a function returns something it stops parsing. You'll need to do it like return array($xmlObj->CountryCode, $xmlObj->City); Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted May 30, 2009 Author Share Posted May 30, 2009 ok i dont thing arraying it is going to work now it is not returning the country correctly :-\ Quote Link to comment Share on other sites More sharing options...
jxrd Posted May 30, 2009 Share Posted May 30, 2009 What's it returning? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted May 30, 2009 Author Share Posted May 30, 2009 nothing it just returns ARRAY Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted May 30, 2009 Author Share Posted May 30, 2009 anyone got any ideas on how to return more than one XML string using arrays or loops ??? Quote Link to comment Share on other sites More sharing options...
jxrd Posted May 30, 2009 Share Posted May 30, 2009 Yeah, well obv it'll return an array if you put it in an array You have to treat it like an array. It will contain the two variables. So... $something = yourfunction(); echo $something[0]; echo $something[1]; Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted May 30, 2009 Author Share Posted May 30, 2009 here is the function i wouldnt know where to start to look <?php function get_ip_location($ip, $format="xml") { /* Set allowed output formats */ $formats_allowed = array("json", "xml", "raw"); /* IP location query url */ $query_url = "http://iplocationtools.com/ip_query.php?ip="; /* Male sure that the format is one of json, xml, raw. Or else default to xml */ if(!in_array($format, $formats_allowed)) { $format = "xml"; } $query_url = $query_url . "{$ip}&output={$format}"; /* Init CURL and its options*/ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $query_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 15); /* Execute CURL and get the response */ //return curl_exec($ch); $response = curl_exec($ch); if ( $format == 'xml' ) { $xmlObj = simplexml_load_string($response); return array( $xmlObj->City, $xmlObj->CountryCode); } } ?> Quote Link to comment Share on other sites More sharing options...
jxrd Posted May 30, 2009 Share Posted May 30, 2009 Ok, so try this: $ip = get_ip_location('127.0.0.1'); print_r($ip); Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted May 30, 2009 Author Share Posted May 30, 2009 yeah i just get ARRAY it doesnt return anything ??? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted May 30, 2009 Author Share Posted May 30, 2009 anyone ??? Quote Link to comment Share on other sites More sharing options...
Michdd Posted May 30, 2009 Share Posted May 30, 2009 Did you try accessing an element of the array?: $ip = get_ip_location('127.0.0.1'); print_r($ip[0]); Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted May 30, 2009 Author Share Posted May 30, 2009 nevermind i got it Quote Link to comment 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.