Page 1 of 1

limit amount of data displayed

Posted: Thu Dec 28, 2006 6:52 pm
by ianhull
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

Posted: Thu Dec 28, 2006 7:00 pm
by jayshields

Code: Select all

substr()

Posted: Thu Dec 28, 2006 10:04 pm
by tarja311
You can try working with :

Code: Select all

$file_length = strlen($file);
						
if($file_length > 150)
{
  $file = substr($file, 0, 150);
  $file = $file."...";	
}
... where after 150 characters it will display the elipse.

Posted: Fri Dec 29, 2006 9:03 am
by Jaxolotl
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;
	}
}

Posted: Fri Dec 29, 2006 9:08 am
by feyd
Check Useful Posts too. ;)