function getFirstWords($string, $words = 1)
{
$string = explode(' ', $string);
if (count($string) > $words)
{
return implode(' ', array_slice($string, 0, $words)) . '...';
}
return implode(' ', $string);
}
echo getFirstWords('Hello, how are you. Some more text.', 2);
source
share