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

Link to comment
Share on other sites

Yeah, well obv it'll return an array if you put it in an array :P

 

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.