如何从谷歌api的货币转换器的符号获得价值

时间:2014-07-22 06:32:06

标签: php mysql ajax codeigniter currency-exchange-rates

我需要将货币从INR转换为other。我通过谷歌货币转换器做到了这一点,但我得到了一个html值,我只需要带符号的值。

我不希望它以html值转换,因为我需要它来传递我的支付网关中的数据。

我的用于获取数据的ajax控制器:

<script>
var currency_url = "<?php echo base_url() ?>products/change_currency/"
function changeCurrency(currency_value){
    $.ajax({
        type:"POST",
        url :currency_url,
        data:{to:currency_value,amount:<?php echo $total_amount;  ?>},
        success:function(data){
            //alert(JSON.parse(data));
            //$('#cuur').html(data);
            alert(data);
        }

    });

}
</script>

PHP CodeIgniter控制器:

public function change_currency()
{

    $from = 'INR';
    $to = $this->input->post('to');
    $amount = $this->input->post('amount');

    $url = "http://www.google.com/finance/converter?a=$amount&from=$from&to=$to"; 

    $req = curl_init();

    $timeout = 0; 
    curl_setopt ($req, CURLOPT_URL, $url); 
    curl_setopt ($req, CURLOPT_RETURNTRANSFER, 1); 

    curl_setopt ($req, CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)"); 
    curl_setopt ($req, CURLOPT_CONNECTTIMEOUT, $timeout); 
    $rawdata = curl_exec($req);


    $data = explode('bld>', $rawdata);
    $data = explode($to, $data[1]);
    $value = round($data[0], 2);
    echo $value;
    exit;

}

当前输出:

555.00
5888.00
4343.00

如果我将INR传递给$

,我需要

然后值应该在$525.00

0 个答案:

没有答案