从Google读取当前人民币汇率中间价

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);
?>

Comments (0)

› No comments yet.

Leave a Reply

Allowed Tags - You may use these HTML tags and attributes in your comment.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

 :wink:  :-|  :-x  :twisted:  :)  8-O  :(  :roll:  :-P  :oops:  :-o  :mrgreen:  :lol:  :idea:  :-D  :evil:  :cry:  8)  :arrow:  :-?  :?:  :!:

Pingbacks (0)

› No pingbacks yet.