I am once again looking for some help.
I have found this stopwords script - I basically remove all common words from a string.
<?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);
?>
The output for the code looks like this:
Array ( [0] => [1] => tag’s [2] => keyword [3] => attribute [4] => page [5] => rank [6] => panacea [7] => prehistoric [8] => days [9] =>)
How can I format it so that the output looks like this: (without开发者_如何转开发 the Array and numbers)
tag's, attribute, page, rank, panacea, prehistoric, days
Thanks
Use implode()
on the resulting array.
$myString = implode( ', ', $myArray ); // Results in Item1, Item2, Item3, etc...
精彩评论