php – Google货币转换器已更改其网址但未获得相同的结果
发布时间:2020-12-13 22:19:21 所属栏目:PHP教程 来源:网络整理
导读:我有以下代码(如下),并使用iGoogle版本. $url = 'http://www.google.com/ig/calculator?hl=enq=' . $amount . $from_Currency . '=?' . $to_Currency; $ch = curl_init(); $timeout = 0; curl_setopt ($ch,CURLOPT_URL,$url); curl_setopt ($ch,CURLOPT_RETU
我有以下代码(如下),并使用iGoogle版本.
$url = 'http://www.google.com/ig/calculator?hl=en&q=' . $amount . $from_Currency . '=?' . $to_Currency; $ch = curl_init(); $timeout = 0; curl_setopt ($ch,CURLOPT_URL,$url); curl_setopt ($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)"); curl_setopt ($ch,CURLOPT_CONNECTTIMEOUT,$timeout); $rawdata = curl_exec($ch); curl_close($ch); $data = explode('"',$rawdata); $data = explode(' ',$data[3]); $var = $data[0]; 但看了他们正在使用不同的URL: 'http://www.google.com/finance/converter?hl=en&a=' . $amount . '&from=' . $from_Currency . '&to=USD'; 但只是更改网址并不会返回我习惯的所需结果. 现在我得到的只是 http://www.w3.org/TR/html4/strict.dtd SO有任何人都在研究这个最新的货币转换器URL或有任何想法.或使用PHP替换 解决方法
感谢一些更深入的查找和重写问题发现这篇文章.所以在某种程度上它是重复的.但问题是:
Need API for currency converting 我使用@hobailey答案进行临时修复,直到我可以将其更新到另一个版本或谷歌决定做一个正确的api. $amount = urlencode($amount); $from_Currency = urlencode($from_Currency); $to_Currency = urlencode($to_Currency); $get = file_get_contents("https://www.google.com/finance/converter?a=$amount&from=$from_Currency&to=$to_Currency"); $get = explode("<span class=bld>",$get); $get = explode("</span>",$get[1]); $converted_amount = preg_replace("/[^0-9.]/",null,$get[0]); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |