PHP 汇率CNY 转换USD 为0怎么办

<?php
//实时获取汇率
http://www.xe.com/ucc/convert.cgi?Amount=1&From=$fix&To=$cur

require("../g.php");
require("../lib/global.php");
$url = "
http://www.xe.com/ucc/convert.cgi?Amount=1&From=$fix&To=$cur
";
$content = file_get_contents($url);
$regex = "/class=\"rate\" >(.+?) ".$cur."/i"; 正则表达式获取内容
if(preg_match_all($regex, $content, $matches)) {
echo $Amount.' CNY = '.$matches[1][0].' '.$to;
echo $matches[0][1];
}
?>
最新回答
旧时青春

2026-04-22 23:25:53

$url = "
http://www.xe.com/ucc/convert.cgi?Amount=1&From=$fix&To=$cur
";
把赋值的双引号换成单引号才能huode全部字符串,否则其中出现的$这些字符都会被当做php代码执行
$url = '
http://www.xe.com/ucc/convert.cgi?Amount=1&From=$fix&To=$cur
';
仙味萝莉

2026-05-28 00:14:41

有可能是缓存导致,你试试另一个浏览器可以不