2017-07-01 52 views
-2

我试图从文本中删除 符号,但是我的方法不起作用。从文本中删除 字符

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。

我为什么有这个符号? 你能否介绍一下它的更多细节?

+2

处理这些类型的使用标准字符串处理函数的字符串(如SUBSTR)的时,这可能是一个问题,如果你需要使用这种方法做任何操作的 - 使用mb_方法(如果可用)(mb_substr)更好地处理多字节字符。 –

回答

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); 
} 
+0

我试过了,但问题仍然出现。 –

+0

@AhmadSamilo你能提供更多的细节吗?它看起来像你试图添加一个省略号的文本,这将意味着你正在截断它,你是否试图清理它之前或之后,你这样做? – apokryfos

+0

这是真的我打电话给这样的方法<?php echo Blog :: cleanText(substr(strip_tags($ model-> introduction),0,$ size);?> –