2

您好喂zend_lucene_search上下文,它可以搜索單詞達到特殊字符,然後它是不可搜索的。如何使用PHP在上下文中刪除不可讀的字符?

例如:

very well to the other job boards � one of the main things that has impressed is the variety of the applications, especially with regards to the background of the candidates" manoj � Head 

如果我搜索「板」我能得到它,但如果我搜索一個或不可讀字符之後的任何字符串,我不能搜索。

如何刪除這些,我想獲得純文本。

我將這些字符轉換成.docx/pdf文件爲文本。

OR

讓我知道如何餵養才Zend_Search_Lucene的文字..

請幫助。

回答

2

您可以使用下面preg_replace函數調用來刪除所有非ASCII(所謂特)從字符串中的字符:

$replaced = preg_replace('/[^\x00-\x7F]+/', '', $str); 
// produces this converted text: 
// "very well to the other job boards one of the main things that has impressed 
// is the variety of the applications, especially with regards to the background of the 
// candidates" manoj Head" 
+0

如果字符包括標點符號或其他可讀的字符? – nageeb

+0

@nageeb:'\ x00- \ x7F'範圍也包含標點符號(ASCII)。 – anubhava

+0

我明白,但我認爲用戶會想保留標點符號。 – nageeb

1

您可能需要將要處理的字符串的字符集轉換爲與當前HTML文檔的字符集相匹配。例如,如果您的HTML文檔使用UTF-8,那麼您可以通過utf8_encode()運行您的字符串。否則,如果您不確定要使用哪個字符集,請嘗試使用mb_convert_encoding()並嘗試使用一些更常見的字符集。

+0

謝謝。我會嘗試與mb_convert_encoding ... –

相關問題