Friday, June 26, 2009

Php - How to display first n words of a paragraph ...


Using this function we can extract first $lemgth words from  $string


<?php

function wordlimit($string, $length = 50, $ellipsis = "...")
{
   
$words = explode(' ', $string);
   if (
count($words) > $length)
       return
implode(' ', array_slice($words, 0, $length)) . $ellipsis;
   else
       return
$string;
}

?>

No comments:

Post a Comment

Popular Hybrid Mobile App development frameworks

Popular Hybrid Mobile App development frameworks Hybrid Development Technologies List of best Hybrid App Development Frameworks ...