如何转换&或任何其他编码的字符使用[PHP]到它的相应的字符?

时间:2016-01-16 17:25:51

标签: php

我需要使用PHP将文本输出到文件,尽管有些文本有&和½我无法确定那些是唯一的,因为文本块非常大。是否有一种非常简单的方法来获取包含这些类型的编码的字符串并将它们转换为各自的字符?

实施例

$str = "It rained 2& frac12 ; inches on friday. (ignore the spaces between & and ;)

当写入文件时,我希望文本阅读:

It rained 2½ inches on friday.

1 个答案:

答案 0 :(得分:0)

html_entity_decode()应该做你需要的!

返回解码字符串的实现示例是;

$str = html_entity_decode($str); //decoded string