doutou7286 2016-02-16 15:36
浏览 33
已采纳

货币转换器(用户输入)

I am searching for a currency converter written in php with a user input, so the user can input a value and then output it. This is the main script.

<?php
    $from_currency = 'EUR';
    $to_currency = 'USD';
    $amount = 1;
    $results = converCurrency($from_currency,$to_currency,$amount);
    $regularExpression = '#\<span class=bld\>(.+?)\<\/span\>#s';
    preg_match($regularExpression, $results, $finalData);
    echo $finalData[0];

    function converCurrency($from,$to,$amount){
        $url = "http://www.google.com/finance/converter?a=$amount&from=$from&to=$to"; 
        $request = curl_init(); 
        $timeOut = 0; 
        curl_setopt ($request, CURLOPT_URL, $url); 
        curl_setopt ($request, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt ($request, CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)"); 
        curl_setopt ($request, CURLOPT_CONNECTTIMEOUT, $timeOut); 
        $response = curl_exec($request); 
        curl_close($request); 
        return $response;
    } 
?>

what do i have to add to this script that the user can put a value of his own.

  • 写回答

1条回答 默认 最新

  • douyi8732 2016-02-16 16:10
    关注

    Google's got some kind of connection limiting on that service, so you'll want to save the results somewhere (as 1 : number) currency units, i.e. 1GBP = 0.65USD

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分