Q:

Limit displayed text length (from DB) in PHP?

I am able to load data off my database into my webpage. However, there are a couple of instances where I would like to limit the number of characters that are placed on a row.
For example, "DESCRIPTION" is a varchar(200), and I only want to show the first 30 characters on this particular page.
<td><?php print $row->DESCRIPTION; ?></td>

What is the best way to go about doing this?
Thanks.
Ended up using this,
<td><?php print substr($row->DESCRIPTION,0,20); ?></td>

A:

I would do it on the php side with substr.
<?php echo substr($row->DESCRIPTION, 30); ?>

Of course that doesnt take into account words and what not so you might need to get more complex with that by writing a custom function if thats important.

