Re: uniq string function?
| From: | Chris Adams | Date: | Wed, 05 Jul 2000 18:33:09 +0000 |
| Subject: | Re: uniq string function? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-5029@lists.php.net to get a copy of this message | ||
> > I am developing a website that is nearly complete sql.
> > I want to generate the meta tags based on content of the
> > sql query returned. Is there a function in php that can
> > give me the unique words in a string containing for
> > example:
> > "baked, black, beans, blackeye, beans, wild, rice, herbs, fit, king,
> > baked, beans, pineapple, baked, beans, tropical, baked, beans american,
> > dry, bean, board, online, cookbook"
> >
> > so that there are not duplicate meta keywords?
>
> For PHP 4:
>
> function uniq_words($str) {
> $arr = explode(',',$str);
> return implode(',',array_keys(array_flip($arr)));
> }
Would there be any benefit to using array_unique() instead?
function uniq_words($str) {
$arr = explode(',',$str);
return implode(',',array_unique($arr));
}