php - 如何使用 PHP 删除上下文中不可读的字符?

标签 php special-characters zend-search-lucene file-conversion read-unread

您好,我正在向 zend_lucene_search 提供上下文,它可以搜索最多特殊字符的单词,之后就无法搜索了。

例如:

    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 

如果我搜索“boards”,我可以找到它,但如果我在不可读的字符之后搜索一个或任何字符串,我无法搜索它。

如何删除这些内容,我想要获取纯文本。

我在将 .docx/pdf 文件转换为文本时遇到了这些字符。

或者

让我知道如何仅向 zend_search_lucene 提供文本..

请帮忙。

最佳答案

您可以使用以下 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"

关于php - 如何使用 PHP 删除上下文中不可读的字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10816966/

相关文章:

php - 无法正常启动XAMPP

javascript - 客户端和服务器端编程有什么区别?

URL 包含非视觉字符

objective-c - 如何将具有特殊字符的字符串拆分为 NSMutableArray

php - Zend_Search_Lucene 的替代品?

php - Zend_Search_Lucene 范围查询错误

java - 一起使用 Solr 和 Zends Lucene 端口

php - 更新在另一个表中找到记录的一个表

java - 如何使 PHP 更加 Javatized(又名强类型,更健壮)?

angular - 仅从 Angular 2+ 将特殊字符粘贴到文本框中时修剪特殊字符