【问题标题】:CodeIgniter is printing unspecified currency(¤) when POST Form data is processed处理 POST 表单数据时,CodeIgniter 正在打印未指定的货币(¤)
【发布时间】:2021-01-06 10:46:02
【问题描述】:

当我在 CodeIgniter 中将字符串打印到浏览器时,我无法删除未指定的货币符号 (¤)。我已经清理了 POST 数据,当我通过 ctrl+u 看到 html 代码用于 chrome 时,它​​就消失了。请帮我删除它。

以下是浏览器上的输出

language=EN&amount=100¤cy=USD&redirect_url=abc.com

 $data='';
    foreach ($_POST as $key => $value){
                     
                     $data.=$key.'='.$value.'&';
                    }
 echo $data;

$_POST 的转储如下,在转储中,货币符号不可见。

array(14) {
    ["country"]=> string(3) "INR" 
    ["language"]=> string(2) "EN" 
    ["amount"]=> string(3) "100" 
    ["currency"]=> string(3) "USD" 
    ["billing_name"]=> string(4) "ABCD" 
    ["billing_email"]=> string(13) "test@test.com" 
    ["billing_tel"]=> string(10) "9876543210" 
    ["billing_address"]=> string(12) "Delhi, India" 
    ["billing_city"]=> string(5) "Delhi" 
    ["billing_state"]=> string(5) "delhi" 
    ["billing_zip"]=> string(6) "110001" 
    ["billing_country"]=> string(5) "India"
} 

【问题讨论】:

  • 你能在你的 foreach 之前提供一个 var_dump($_POST) 吗?你是如何清理 $_POST 的?
  • $_POST 的转储如下,转储中的货币符号不可见。 array(14) { ["country"]=> string(3) "INR" ["language"]=> string(2) "EN" ["amount"]=> string(3) "100" ["currency "]=> string(3) "USD" ["billing_name"]=> string(4) "ABCD" ["billing_email"]=> string(13) "test@test.com" ["billing_tel"]=> string(10) "9876543210" ["billing_address"]=> string(12) "印度德里" ["billing_city"]=> string(5) "德里" ["billing_state"]=> string(5) "德里" ["billing_zip"]=> 字符串(6) "110001" ["billing_country"]=> 字符串(5) "印度" }

标签: php codeigniter google-chrome


【解决方案1】:

所以你看到的是这个......

language=EN&amount=100¤cy=USD&redirect_url=abc.com

你应该看到的是这个......

language=EN&amount=100&currency=USD&redirect_url=abc.com

所以观察到的输出缺少 &curren 被您看到的字符替换。

解决这个问题的方法是使用 htmlentities 来阻止这种翻译。

所以你的代码会变成

foreach ($_POST as $key => $value){
  $data .= $key.'='.$value.'&';
}
$data = trim($data, '&'); // hack to remove last &
echo htmlentities($data); // This will give the correct result

仅供参考(来自维基百科)货币符号在 Unicode 中表示为 U+00A4 ¤ CURRENCY SIGN (HTML ¤ ; · &curren ;) **在每个 ; 让它显示

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-30
    • 2023-04-04
    • 1970-01-01
    • 2012-01-22
    • 1970-01-01
    • 1970-01-01
    • 2021-12-27
    • 1970-01-01
    相关资源
    最近更新 更多