从Google读取当前人民币汇率中间价
Feb 01
Web|PHP|MySQL|jQuery No Comments
php
<?php function findstr($line,$condi,$num){ $a = strpos($line, $condi); $arr = explode(' ', substr($line, $a+$num, 20)); return $arr[0]; } $url = "http://www.google.com/search?&q=1usd%3D%3Frmb"; //usd $str = file_get_contents($url); preg_match_all("/1 U.S. dollar = .* Chinese yuan/", $str, $arr); $rate['usd'] = findstr($arr[0][0], '= ', 2); $url = "http://www.google.com/search?&q=1eur%3D%3Frmb"; //eur $str = file_get_contents($url); preg_match_all("/1 Euro = .* Chinese yuan/", $str, $arr); $rate['eur'] = findstr($arr[0][0], '= ', 2); print_r($rate); ?>