Limit number of characters

I have this code

echo "<div id=\\"mainimages\\"><p>" . $row['title'] . "<br /></b></p>";

I need to limit the number of characters that are output from the title.

Can anyone tell me how please?

Amazing - problem solved once again. I love this forum!

<?php echo current(explode('__break__', wordwrap($str, 50, '__break__'))); ?>

* where 50 is your max length. :wink:


echo "<div id=\\"mainimages\\"><p>" . current(explode('__break__', wordwrap($row['title'], 50, '__break__'))) . "<br /></b></p>";

Sorry to be a complete noob but how does your line fit into what I have here?

 echo "<div id=\\"mainimages\\"><p>" . substr($row['title'], 0, 12) . "<br /></b></p>";

Example: You can do substr, which means start at 0, and end at 50 characters.

echo substr($row['title'], 0, 50);

nice one that work’s like a charm :slight_smile:

How can I now make it chop off whole words only. I mean so that I don’t get parts of word’s. Still not exceeding the char limit.