gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 05:44:49 24 4
gpt4 key购买 nike

嗨,正在向 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com