从文本中删除 字符

时间:2017-07-01 07:01:19

标签: php regex unicode

我正在尝试从文本中删除 符号,但我的方法无效。

enter image description here

这是我删除符号的代码。

public static function cleanText($text) {
    $textStripped = strip_tags($text);                  // Strip HTML Tags
    $textStripped = html_entity_decode($textStripped);  // Clean up things like &
    $textStripped = urldecode($textStripped);           // Strip out any url-encoded stuff
    return $textStripped;
}

页面编码为utf-8。

为什么我有这个符号? 你能详细介绍一下吗?

1 个答案:

答案 0 :(得分:1)

这是一个无效的UTF-8字符(可能是某些内容被截断的结果)。您可以使用iconv

删除它们
public static function cleanText($text) {
    $textStripped = strip_tags($text);                  // Strip HTML Tags
    $textStripped = html_entity_decode($textStripped);  // Clean up things like &
    $textStripped = urldecode($textStripped);           // Strip out any url-encoded stuff
    return iconv("UTF-8","UTF-8//IGNORE",$textStripped);
}