2017-07-01 53 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);?> –