Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何设定印度卢比和印度美元的产品价格?_Php_Currency - Fatal编程技术网

Php 如何设定印度卢比和印度美元的产品价格?

Php 如何设定印度卢比和印度美元的产品价格?,php,currency,Php,Currency,我正在开发电子商务网站。我几乎做到了。但我有一个问题,就是用美元来显示产品价格。如果用户在印度打开的网站以卢比显示产品价格,如果用户在国外访问的网站以美元显示产品价格 我创建了产品详细信息页面,下面提供了我的代码: public function getProductDetail($pro_code,$error_msg){ $showProDetail=''; $result =$this->connect()->query("SELECT * FROM wm_products W

我正在开发电子商务网站。我几乎做到了。但我有一个问题,就是用美元来显示产品价格。如果用户在印度打开的网站以卢比显示产品价格,如果用户在国外访问的网站以美元显示产品价格

我创建了产品详细信息页面,下面提供了我的代码:

public function getProductDetail($pro_code,$error_msg){
$showProDetail='';
$result =$this->connect()->query("SELECT * FROM wm_products WHERE pro_code='$pro_code'");
if($result->num_rows>0){            
    $row = $result->fetch_assoc();
    $cate_id = $row['cate_id'];         
    $image = json_decode($row['pro_img']);
    $showProDetail.='
    <div class="page product_detail_wrapper">
        <div class="panel-body">
            <div class="row">
                <div class="col-lg-4 col-mg-4 col-sm-4 col-xs-12">
                    <figure class="thumbnail">
                        <img src="../uploads/product_images/' .$image[0].'" alt="">
                    </figure>
                </div>
                <div class="col-lg-8 col-mg-8 col-sm-8 col-xs-12">
                    <div class="responsive-table">
                        <table class="table table-striped">                             
                            <tr>
                                <td><strong>Product Code</strong></td>
                                <td>:'.$row["pro_code"].'</td>
                            </tr>
                            <tr>
                                <td><strong>Name</strong></td>
                                <td>:'.ucfirst(str_replace("_", " ", $row["pro_name"])).'</td>
                            </tr>                   
                            <tr>
                                <td><strong>Price</strong></td>
                                <td>: Rs.'.$row["pro_price"].'</td>
                            </tr>
                            <tr>
                                <td><strong>Discount</strong></td>
                                <td>:'.$row["pro_discount"].'</td>
                            </tr>
                            <tr>
                                <td><strong>Available In</strong></td>
                                <td>:'.$row["pro_weight"].'</td>
                            </tr>
                            <tr>
                                <td><strong>Quantity</strong></td>
                                <td>:'.$row["pro_quantity"].'</td>
                            </tr>
                            <tr>
                                <td><strong>Short Description</strong></td>
                                <td>:'.$row["short_disc"].'</td>
                            </tr>                                   
                        </table>
                    </div>
                </div>
            </div><br>              
        </div>
    </div>';
}
else{
    $showProDetail = '<div class="alert alert-danger">Product Detail Not Found</div>';
}
return  $showProDetail;
}
公共函数getProductDetail($pro\u code,$error\u msg){
$showProDetail='';
$result=$this->connect()->query(“从wm_产品中选择*,其中pro_代码=“$pro_代码”);
如果($result->num_rows>0){
$row=$result->fetch_assoc();
$cate_id=$row['cate_id'];
$image=json_decode($row['pro_img']);
$showProDetail.='
产品代码
:'.$row[“专业代码”]。'
名称
:“.ucfirst(str_replace(“_”,”,$row[“pro_name”))。”
价格
:卢比。.$行[“专业价格”]。'
折扣
:“.$row[“专业折扣”]。”
可在
:“.$row[“pro_重量”]”
数量
:“.$行[“专业数量”]。”
简短描述
:“.$row[“short_disc”]”

'; } 否则{ $showProDetail='未找到产品详细信息'; } 返回$showProDetail; }

那么,如何设置印度卢比和印度美元的产品价格呢?

要设置产品价格,您需要执行以下4个步骤:

1. 获取访客位置。因此,您可以使用HTML地理位置API定位访客的当前位置。在这里,您可以找到关于如何在PHP中使用HTML5地理定位API获取访问者位置的教程。

2. 将货币从印度卢比转换为美元。因为您需要为非印度游客的产品设置美元价格。因此,要将印度卢比转换为美元,您可以使用以下源代码:

function currency($amount) {
 $from_currency = "INR";
 $to_currency = "USD";
 $from_currency = urlencode($from_currency);
 $to_currency = urlencode($to_currency);
 $url = "https://www.google.com/search?q=".$from_currency."+to+".$to_currency;
 $get = file_get_contents($url);
 $data = preg_split('/\D\s(.*?)\s=\s/',$get);
 $exhangeRate = (float) substr($data[1],0,7);
 $converted_amount  = $amount*$exhangeRate;
 return $converted_amount;
}
  • getProductDetail函数中,您可以检查访问者的位置。在$showProDetail语句上方,您可以通过以下过程进行检查:

    if($location == 'India') {
        $price = "Rs.".$row["pro_price"];
    } else {
        $price = "USD.".currency($row["pro_price"]);
    }
    
  • 最后,您可以直接将产品价格放入您的价格td中。

    <tr>
        <td><strong>Price</strong></td>
        <td>:'.$price.'</td>
    </tr>
    
    
    价格
    :“.$price。”
    

  • 您可以使用ip跟踪web用户所在国家/地区。这个问题在这里已经有了答案。代码中可能存在重复的获取错误警告:文件\u获取\u内容():无法打开流:HTTP请求失败!HTTP/1.0 403禁止这意味着您在共享主机中,文件获取内容被阻止。或者,您可以使用curl获取结果。谷歌资讯科技&你会发现许多链接来执行这个。感谢布彭德拉·杜德瓦尔你的代码为我工作。欢迎钱丹·贾哈
     $amount=100; //Your ammount
     $from_currency = "INR";
     $to_currency = "USD";
     $from_currency = urlencode($from_currency);
     $to_currency = urlencode($to_currency);
     $url = "https://www.google.com/search?q=".$from_currency."+to+".$to_currency;
     $get = file_get_contents($url);
     $data = preg_split('/\D\s(.*?)\s=\s/',$get);
     $exhangeRate = (float) substr($data[1],0,7);
     $converted_amount  = $amount*$exhangeRate;
    
    
    
    
    please use $url = "https://www.google.com/search?q=".$from_currency."+to+".$to_currency;