【问题标题】:How can I convert ANSI Extended ASCII (Windows) to UTF-8 or html entities with PHP? [duplicate]如何使用 PHP 将 ANSI 扩展 ASCII (Windows) 转换为 UTF-8 或 html 实体? [复制]
【发布时间】:2013-01-29 15:16:28
【问题描述】:

可能重复:
PHP Ansi to UTF-8

我的数据偶尔包含各种 ANSI Windows ASCII 字符(例如,x99 代表 TM,xA9 代表版权,xAE 代表注册商标等)。这些字符无法在网页中正确显示。

PHP 中有一个函数可以让我自动正确地转换它们吗?或者,我是否必须有大量的 str_replace() 调用分别进行每个替换?如果我必须使用 str_replace(),匹配 ANSI 代码的正确方法是什么?我在想这样的事情:

$str = str_replace('/\x99','™',$str); // trademark symbol

有没有更好的办法?

【问题讨论】:

  • 你应该看看 iconv PHP 函数。

标签: php str-replace ansi


【解决方案1】:

查看 htmlentities

http://php.net/manual/en/function.htmlentities.php

它将< 转换为<,将ö 转换为ö 等等...

【讨论】:

  • 我试过iconv,问题是数据不一致。这变得非常令人沮丧。
猜你喜欢
  • 1970-01-01
  • 2023-03-18
  • 2020-04-12
  • 1970-01-01
  • 2012-08-04
  • 1970-01-01
  • 2023-03-19
  • 1970-01-01
  • 2011-05-20
相关资源
最近更新 更多