Limiting the amount of text returned from a query in PHP


<?php
$text = “Hand picked gift ideas for geeks from the geeky gift experts  don’t worry if you aren’t a geeky person yourself, we’ve got some of the coolest geeky products from video game geek stuff to nostalgic geek things to please even the most difficult, hardcore, and obscure geeks.Hand picked gift ideas for geeks from the geeky gift experts  don’t worry if you aren’t a geeky person yourself, we’ve got some of the coolest geeky products from video game geek stuff to nostalgic geek things to please even the most difficult, hardcore, and obscure geeksrson yourself, we’ve got some of the coolest geeky products from video game geek stuff to nostalgic geek things to please even the most difficult, hardcore, and obscure geeks.Hand picked gift ideas for geeks from the geeky gift experts  don’t worry if you aren’t a geeky person yourself, we’ve got some of the coolest geeky products from video game geek stuff to nostalgic geek things to please even the most difficult, hardcore, and obscure geeks.”;

function trunc($phrase, $max_words=50)
{
$phrase_array = explode(‘ ‘,$phrase);
if(count($phrase_array) > $max_words && $max_words > 0)
$phrase = implode(‘ ‘,array_slice($phrase_array, 0, $max_words));
echo $phrase;
}

trunc($text);

?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s