joomla
asked on
First X words in formatted string
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
{
$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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you