<?php
$Amount = $_GET['Amount'];
$to = $_GET['to'];
$url = "http://www.xe.com/ucc/convert.cgi?Amount=$Amount&From=CNY&To=$to";
$content = file_get_contents($url);
$regex = "/class=/"rate/" >(.+?) ".$to."/i"; //正则表达式.
if(preg_match_all($regex, $content, $matches)) {
echo $Amount.' CNY = '.$matches[1][0].' '.$to;
}
?>
Amount为金额数量,to为目标货币的代号,From=CNY中的CNY为人民币的代号,这里是直接写死在了网址后面的参数上。通过正则将查询出来的结果过滤到我们想要的结果,然后呈现出来。目标达到。