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 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大