PHP Help Please

Discussion in 'PHP' started by ChristopherLeeMaher.Com, Sep 26, 2010.

  1. #1
    Hello,

    I have a PHP code
    
    <?php
    $file = file('http://gd.geobytes.com/gd?after=-1&variables=GeobytesCountry');
    if (in_array(Australia, $file)) {
    echo '<li><a href="http://xxx.com.au/" title="XXXX">XXX</a></li>';
    }
    ?>
    
    PHP:
    What i want it to do is in http://gd.geobytes.com/gd?after=-1&variables=GeobytesCountry if that files has Australia is will echo

    Thanks
     
    ChristopherLeeMaher.Com, Sep 26, 2010 IP
  2. xrvel

    xrvel Notable Member

    Messages:
    918
    Likes Received:
    30
    Best Answers:
    2
    Trophy Points:
    225
    #2
    <?php
    $file = file_get_contents('http://gd.geobytes.com/gd?after=-1&variables=GeobytesCountry');
    if (preg_match('/Australia/i', $file)) {
    	echo '<li><a href="http://xxx.com.au/" title="XXXX">XXX</a></li>';
    }
    ?>
    PHP:
     
    xrvel, Sep 26, 2010 IP
  3. ChristopherLeeMaher.Com

    ChristopherLeeMaher.Com Guest

    Messages:
    185
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hey it isn't working?
     
    ChristopherLeeMaher.Com, Sep 26, 2010 IP
  4. xrvel

    xrvel Notable Member

    Messages:
    918
    Likes Received:
    30
    Best Answers:
    2
    Trophy Points:
    225
    #4
    It is not working?

    Try this then, and let me know what's the output.
    <?php
    $file = file_get_contents('http://gd.geobytes.com/gd?after=-1&variables=GeobytesCountry');
    if (preg_match('/Australia/i', $file)) {
    	echo '<li><a href="http://xxx.com.au/" title="XXXX">XXX</a></li>';
    } else {
    	echo 'Invalid';
    	var_dump($file);
    }
    ?>
    PHP:
     
    xrvel, Sep 26, 2010 IP
  5. ChristopherLeeMaher.Com

    ChristopherLeeMaher.Com Guest

    Messages:
    185
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    it doesn't work eather
     
    ChristopherLeeMaher.Com, Sep 26, 2010 IP
  6. xrvel

    xrvel Notable Member

    Messages:
    918
    Likes Received:
    30
    Best Answers:
    2
    Trophy Points:
    225
    #6
    Okay, final code... :rolleyes:

    <?php
    if (!function_exists('curl_init')) {
    	echo 'Curl is not enabled.';
    	exit();
    }
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'http://gd.geobytes.com/gd?after=-1&variables=GeobytesCountry');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($ch, CURLOPT_TIMEOUT, 94);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 94);
    $file = curl_exec($ch);
    $info = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    
    if (preg_match('/Australia/i', $file)) {
        echo '<li><a href="http://xxx.com.au/" title="XXXX">XXX</a></li>';
    } else {
        echo 'Invalid.<br />';
        var_dump($file);
    }
    ?>
    PHP:
     
    xrvel, Sep 26, 2010 IP
  7. Media Signal

    Media Signal Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    $data = file_get_contents('http://gd.geobytes.com/gd?after=-1&variables=GeobytesCountry');
    
    if (strstr($data, "Australia")) {
    
    	echo '<li><a href="http://xxx.com.au/" title="XXXX">XXX</a></li>';
    	
    } else {
    
    	echo "Sorry, you are not from Australia ..";
    	
    }
    PHP:
     
    Media Signal, Sep 26, 2010 IP