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; } ?> Link to comment https://forums.phpfreaks.com/topic/160284-solved-xml-wont-return-more-than-one-string/ 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? Link to comment https://forums.phpfreaks.com/topic/160284-solved-xml-wont-return-more-than-one-string/#findComment-845874 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 Link to comment https://forums.phpfreaks.com/topic/160284-solved-xml-wont-return-more-than-one-string/#findComment-845875 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 :-\ Link to comment https://forums.phpfreaks.com/topic/160284-solved-xml-wont-return-more-than-one-string/#findComment-845877 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); Link to comment https://forums.phpfreaks.com/topic/160284-solved-xml-wont-return-more-than-one-string/#findComment-845878 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 :-\ Link to comment https://forums.phpfreaks.com/topic/160284-solved-xml-wont-return-more-than-one-string/#findComment-845884 Share on other sites More sharing options...
jxrd Posted May 30, 2009 Share Posted May 30, 2009 What's it returning? Link to comment https://forums.phpfreaks.com/topic/160284-solved-xml-wont-return-more-than-one-string/#findComment-845885 Share on other sites More sharing options...
darkfreaks Posted May 30, 2009 Author Share Posted May 30, 2009 nothing it just returns ARRAY Link to comment https://forums.phpfreaks.com/topic/160284-solved-xml-wont-return-more-than-one-string/#findComment-845886 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 ??? Link to comment https://forums.phpfreaks.com/topic/160284-solved-xml-wont-return-more-than-one-string/#findComment-845902 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]; Link to comment https://forums.phpfreaks.com/topic/160284-solved-xml-wont-return-more-than-one-string/#findComment-845903 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); } } ?> Link to comment https://forums.phpfreaks.com/topic/160284-solved-xml-wont-return-more-than-one-string/#findComment-845905 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); Link to comment https://forums.phpfreaks.com/topic/160284-solved-xml-wont-return-more-than-one-string/#findComment-845907 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 ??? Link to comment https://forums.phpfreaks.com/topic/160284-solved-xml-wont-return-more-than-one-string/#findComment-845910 Share on other sites More sharing options...
darkfreaks Posted May 30, 2009 Author Share Posted May 30, 2009 anyone ??? Link to comment https://forums.phpfreaks.com/topic/160284-solved-xml-wont-return-more-than-one-string/#findComment-845923 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]); Link to comment https://forums.phpfreaks.com/topic/160284-solved-xml-wont-return-more-than-one-string/#findComment-845927 Share on other sites More sharing options...
darkfreaks Posted May 30, 2009 Author Share Posted May 30, 2009 nevermind i got it Link to comment https://forums.phpfreaks.com/topic/160284-solved-xml-wont-return-more-than-one-string/#findComment-845985 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.