function first_words($string, $num)
$words = str_word_count($string, 2);
$firstwords = array_slice( $words, 0, $num);
return implode(' ', $firstwords);
I use this PHP function to get the first X number of words from a field in a mysql table.
In an ideal world it works, however if the field contains html tags "<p>" etc... they are included in the string that is returned.
I want to ignore all formatting and simply get the first 10 words in the field