由于应用程序中的编码问题,我需要将Microsoft Word版本的单引号和双引号(“ ” ‘ ’
)替换为常规引号(‘和")。我不需要它们是HTML实体,也不能更改我的数据库模式。
我有两个选择:使用正则表达式或关联的数组。
有没有更好的方法来做这件事?
发布于 2011-07-07 20:40:19
我已经找到了这个问题的答案。你只需要一行代码就可以在php中使用iconv()
函数:
// replace Microsoft Word version of single and double quotations marks (“ ” ‘ ’) with regular quotes (' and ")
$output = iconv('UTF-8', 'ASCII//TRANSLIT', $input);
发布于 2009-08-11 20:31:19
我们使用了以下代码。它处理更多的特殊字符。
$text = str_replace(chr(130), ',', $text); // Baseline single quote
$text = str_replace(chr(132), '"', $text); // Baseline double quote
$text = str_replace(chr(133), '...', $text); // Ellipsis
$text = str_replace(chr(145), "'", $text); // Left single quote
$text = str_replace(chr(146), "'", $text); // Right single quote
$text = str_replace(chr(147), '"', $text); // Left double quote
$text = str_replace(chr(148), '"', $text); // Right double quote
$text = mb_convert_encoding($text, 'HTML-ENTITIES', 'UTF-8');
https://stackoverflow.com/questions/1262038
复制相似问题