Jump to content

[SOLVED] XML wont return more than one string


darkfreaks

Recommended Posts

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;
        } ?>

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);
	} 


    }
    ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.