【问题标题】:Currency symbol is not displaying properly in PHP货币符号在 PHP 中无法正确显示
【发布时间】:2019-11-15 07:17:07
【问题描述】:

货币符号显示不正确。 以下是我的代码:

$total = "₮50.40";
echo $total."<br>"; //output: ₮50.40

$str3 = substr($total, 0, 1);

echo $str3; //output: �

变量$total 显示正确。但是我从$total 中提取符号并显示它,不幸的是它显示了...。

我想显示来自变量$total 的₮。 我尝试了utf8 编码,但没有运气。

【问题讨论】:

    标签: php currency


    【解决方案1】:

    字符是多字节字符,所以需要使用mb_substr,而不是substr

    $total = "₮50.40";
    $str3 = mb_substr($total, 0, 1);
    echo $str3;
    

    输出:

    Demo on 3v4l.org

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-22
      • 1970-01-01
      • 2021-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多