hi guys,
another one for you,
i have a details field and i would like to retrieve and only display the first 150 characters then show a "..."
how is this done? php5 mysql5
you see pages that start a sentence and then show ...more>> etc.
please help
thanks
limit amount of data displayed
Moderator: General Moderators
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Code: Select all
substr()You can try working with :
... where after 150 characters it will display the elipse.
Code: Select all
$file_length = strlen($file);
if($file_length > 150)
{
$file = substr($file, 0, 150);
$file = $file."...";
}- Jaxolotl
- Forum Contributor
- Posts: 137
- Joined: Mon Nov 13, 2006 4:19 am
- Location: Argentina and Italy
I use this to prevent truncate words and breaking tags
Code: Select all
function reduceText($string)
{
$string = strip_tags($string);
//Search the end of a word after [, int offset] and set the result as limit
$limit = @strpos($string, " ",150);
if($limit){
//Use $limit to replace width ...Text
return substr_replace($string, "...",$limit);
}
else{
return $string;
}
}