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
<?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:
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:
Okay, final code... <?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:
$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: