用PHP转换Microsoft Word特殊字符

前端之家收集整理的这篇文章主要介绍了用PHP转换Microsoft Word特殊字符前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试转换包含MS Word省略号和长破折号的用户粘贴的Word文本,然后进一步处理它.

我在这里找到了一个旧的解决方案,解决了这个问题http://www.codingforums.com/archive/index.php/t-47163.html,但是对我来说并不奏效.更换省略号后,该变量返回为空.从来没有见过这样的事情:

$src = "Long word dash – and weird Word ellipsis…";
$src = str_replace("‘","'",$src);
$src = str_replace("’",$src);
$src = str_replace("”",'"',$src);
$src = str_replace("“",$src);
$src = str_replace("–","-",$src);
$src = str_replace("…","...",$src);
print $src;

有任何想法吗?

对于在PHP中获得钻石问号的人来说,替代UTF-8字符的方法比使用chr函数更有效.
$search = [                 // www.fileformat.info/info/unicode/<NUM>/ <NUM> = 2018
                "\xC2\xAB",// « (U+00AB) in UTF-8
                "\xC2\xBB",// » (U+00BB) in UTF-8
                "\xE2\x80\x98",// ‘ (U+2018) in UTF-8
                "\xE2\x80\x99",// ’ (U+2019) in UTF-8
                "\xE2\x80\x9A",// ‚ (U+201A) in UTF-8
                "\xE2\x80\x9B",// ‛ (U+201B) in UTF-8
                "\xE2\x80\x9C",// “ (U+201C) in UTF-8
                "\xE2\x80\x9D",// ” (U+201D) in UTF-8
                "\xE2\x80\x9E",// „ (U+201E) in UTF-8
                "\xE2\x80\x9F",// ‟ (U+201F) in UTF-8
                "\xE2\x80\xB9",// ‹ (U+2039) in UTF-8
                "\xE2\x80\xBA",// › (U+203A) in UTF-8
                "\xE2\x80\x93",// – (U+2013) in UTF-8
                "\xE2\x80\x94",// — (U+2014) in UTF-8
                "\xE2\x80\xA6"  // … (U+2026) in UTF-8
    ];

    $replacements = [
                "<<",">>","<",">","..."
    ];

    str_replace($search,$replacements,$string);
原文链接:https://www.f2er.com/php/132105.html

猜你在找的PHP相关文章