是否有一个函数可以从一个小长度的字符串中剪切单词,例如,和,you,me,或,所有这些在所有句子中都很常见的短词。我想使用这个函数来用标准填充全文搜索。
在采用该方法之前:
$fulltext = "there is ongoing work on creating a formal PHP specification.";结果:
$fulltext_method_solution = "there ongoing work creating formal specification."发布于 2015-08-31 07:01:14
$fulltext = "there is ongoing work on creating a formal PHP specification.";
$words = array_filter(explode(' ', $fulltext), function($val){
return strlen($val) > 3; // filter words having length > 3 in array
});
$fulltext_method_solution = implode(' ', $words); // join words into sentence发布于 2015-08-31 06:57:16
试试这个:
$fulltext = "there is ongoing work on creating a formal PHP specification.";
$result=array();
$array=explode(" ",$fulltext);
foreach($array as $key=>$val){
if(strlen($val) >3)
$result[]=$val;
}
$res=implode(" ",$result);发布于 2015-08-31 06:58:16
试试这个:
$stringArray = explode(" ", $fulltext);
foreach ($stringArray as $value)
{
if(strlen($value) < 3)
$fulltext= str_replace(" ".$value." " ," ",$fulltext);
}这里是一个工作 \n">演示
https://stackoverflow.com/questions/32305449
复制相似问题