Click to See Complete Forum and Search --> : Limit an echo


Perfidus
12-04-2003, 06:39 AM
I wonder how can I limit an echo:

Custmers write description of their products and after I echo them:

<? echo $row['Descripcion']; ?>

But sometimes descrption is too long and I would like to show only the first 350 characters of the description, because tables look very bad when description is too long.

How can I do that?

Pittimann
12-04-2003, 06:51 AM
Hi!

Something like that would help:

<?
if (strlen($row['Descripcion'])<=350){
echo $row['Descripcion'];
}
else{
echo substr($row['Descripcion'], 0, 350);
}
?>

Cheers - Pit

pyro
12-04-2003, 07:43 AM
You should probably also enter something at the end, so people know that the description has been altered...

Pittimann
12-04-2003, 07:48 AM
Hi!

Absolutely correct, pyro!! I should have added something like that in the "else" part - I simply forgot it. Thanks!

Cheers - Pit

pyro
12-04-2003, 07:54 AM
No problem... :)