1 2 3 4 5 6 7 8
<?php function getFirstXWord($string, $a) { $temp = explode(" ", $string); return implode(" ", array_slice($temp, 0, $a, true)); } echo getFirstXWord("this is a content but do not trust this content", 5); ?>
1
this is a content but