0

Just want to show current gold rate from Gold Price India (http://www.goldpriceindia.com/) using PHP.

I have done to get data using file_get_contents() method. But its working on localhost but not in server. I want this on my FTP server too.

My Code:

$url1 = 'http://www.goldpriceindia.com/gold-price-kolkata.php';
$content1 = file_get_contents($url1);
$first_step1 = explode( '<div class="prc">' , $content1 );
$gold_rate1 = explode("</div>" , $first_step1[1] );

I am using PHP, I hope my question is clear if not I ready to explain again.

Thank You.

Debanjan Roy
  • 21
  • 1
  • 8

2 Answers2

1

may be your server disabled URL file access may be you can try alternate solution to get file content.

Alternate method to get file content

   function url_get_contents ($Url) {
if (!function_exists('curl_init')){ 
    die('CURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
Community
  • 1
  • 1
Sushil Mate
  • 583
  • 6
  • 14
  • Usually if they disable URL file access, they also disable `cURL`, since the goal is to prevent accessing remote URLs in general. – Barmar Jul 09 '16 at 08:15
  • You can make HTTP requests without cURL, too, though it requires allow_url_fopen to be enabled in your php.ini file. I don't think so they disabled CURL, cURL is a way you can hit a URL from your code to get a html response from it. cURL means client URL which allows you to connect with other URLs and use their responses in your code. – Sushil Mate Jul 09 '16 at 08:50
1

100% working Code

preg_match('#Gold price today in India <b>\(Rs\/10gm\)</b> is <b>([0-9\.]+)#', file_get_contents('http://www.marketonmobile.com/gold_price_india.php'), $matches);

echo 'The price is: '.$matches[1];

jack jones
  • 11
  • 2
  • '
    ([0-9\.]+)#
    ', file_get_contents('http://www.ibplspot.com/index.php/C_booking/index'), $matche);' this is not working can u see this?
    – Salman Riyaz Oct 25 '17 at 19:06