我想使用PHP显示Gold Price India网站目前的GOLD RATE

时间:2016-07-09 07:10:58

标签: php

只想使用PHP显示金价印度(http://www.goldpriceindia.com/)的当前黄金汇率。

我已经完成了使用file_get_contents()方法获取数据。但是它在localhost上工作但不在服务器上工作。我也想在我的FTP服务器上使用它。

我的代码:

$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] );

我正在使用PHP,我希望我的问题很清楚,如果不是我准备再解释一下。

谢谢。

2 个答案:

答案 0 :(得分:1)

可能是您的服务器禁用的URL文件访问可能是您可以尝试替代解决方案来获取文件内容。

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

答案 1 :(得分:1)

100%正常工作代码

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);
回声&#39;价格是:&#39;。$匹配[1];