Tuesday 28 May 2013

Limit total words to be displayed - PHP

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