Wednesday 19 March 2014

Get as much word as you like from a string (PHP).

e.g. Get 5 first word from a string;
<?php
$string="It is array slice that fetch 5 word from this string";
$m=implode(' ', array_slice(str_word_count($string, 2), 0, 5));
echo "$m";
?>

Output: It is array slice that

No comments:

Post a Comment