How to limit total words to be display in php
<?php
function get_words($text, $len){
$array = explode(" ", $text, $len+1);
if(count($array)>$len){
unset($array[$len]);
}
return implode(" ", $array);
}
$text = "This is a testing for limit word display.";
echo get_words($text, 3);
?>
No comments:
Post a Comment