我再次寻求帮助。
我找到了这个停用词脚本 - 我基本上从字符串中删除了所有常见单词。
<?php
$CommonWords = file_get_contents('http://localhost/stopwords.txt');
$CommonWords = explode("\n", $CommonWords);
$CommonWords = array_map('trim', $CommonWords); // <---- ADD THIS LINE
$keywords = 'The <meta> tag’s keyword attribute is not the page rank panacea it once was back in the prehistoric days of Internet search. It was abused far too much and lost most of its cachet. But there’s no need to ignore the tag. Take advantage of all legitimate opportunities to score keyword credit, even when the payoff is relatively low. Fill in this tag’s text with relevant keywords and phrases that describe that page’s content';
$search_keywords = strtolower(trim($keywords));$arrWords = explode(' ', $search_keywords);
$arrWords = array_unique($arrWords);
foreach ($arrWords as $word) {
if (!in_array($word, $CommonWords) && (trim($word) != ''))
{
$searchWords[] = $word;
}
}
print_r($searchWords);
?>
代码的输出如下所示:
Array ( [0] => [1] => tag’s [2] => keyword [3] => attribute [4] => page [5] => rank [6] => panacea [7] => prehistoric [8] => days [9] =>)
如何格式化它以使输出看起来像这样:(没有数组和数字)
tag's, attribute, page, rank, panacea, prehistoric, days
Thanks
Use implode() http://php.net/manual/en/function.implode.php在结果数组上。
$myString = implode( ', ', $myArray ); // Results in Item1, Item2, Item3, etc...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)