【发布时间】:2016-08-17 07:27:07
【问题描述】:
我的价格值前面有英镑符号。我需要删除那个标志。
$price = '£3.76' (This comes from database and is stored as a string within the database)
1) preg_replace('/[\£]/', '', $price);
2) ltrim($price, '£');
3) str_replace(utf8_decode("£"),"",utf8_decode($price));
4) str_replace('£', '', $price);
我尝试使用一切,但没有任何效果。 1 和 4 替换为 Â,而 2 和 3 将 Â 添加到值的左侧。谁能帮帮我。
【问题讨论】:
-
以上哪个命令会产生您所看到的输出?请发布包含价格值的完整字符串作为示例,以便我们有一个真实的示例来帮助您。
-
我已经编辑了这个问题,如果现在更清楚了,请告诉我。
-
如果您在浏览器中看到
Â,这是因为服务器发送的内容类型字符编码不正确。您可以在脚本中添加header('Content-type: text/html; charset=utf-8');以正确查看井号。但是$price = str_replace('£', '', $price);可以很好地删除它。 -
还要检查并确保数据库是 utf-8 Collation
-
@drew010 我正在导出 csv 文件中的数据,我在文件中看到了 Â。
标签: php