Click to See Complete Forum and Search --> : str_word_count help please


tall1
01-21-2006, 10:46 PM
I know this is probably an easy one but I can't figure it out.

$word_count_array = str_word_count($description, 1);

I simply need to get the first 50 words out of $word_count_array and assign it to $word_count_string.

Please help. Thanx

NogDog
01-22-2006, 12:02 AM
I think this will work:

$word_count_string = implode(" ", array_splice($word_count_array, 0, 50));

Note however that you are going to lose any punctuation (and probably numbers) with your current implementation of str_word_count(). You might consider adding any such characters you wish to preserve into the optional 3rd parameter to that function.