1

我需要将货币从 转换INRother。我通过谷歌货币转换器做到了这一点,但我得到了一个 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

4

0 回答 0