Hi guys. Im a clueless hobbyist with a little problem I cant solve. I hope I can explain it well enought to be understood.
I have been trying to use the substr() function to show a the first few line of my aricles and then give a link to the full article. Unfortunately i get broken words and it make my blog very messy.

This is how i've been trying to do it:

<?php echo substr(nl2br($row_getPosts['entry']),0, 600); ?>

Ive googled solutions and the seem very complex for someone like me. Please help.


You can try reading this . The author wrote a function as shown below...

   function truncate_str($str, $maxlen) {
if ( strlen($str) <= $maxlen ) return $str;

$newstr = substr($str, 0, $maxlen);
if ( substr($newstr,-1,1) != ' ' ) $newstr = substr($newstr, 0, strrpos($newstr, " "));

return $newstr;

and to use it on your applications, it can be as simple as this..

$summary = truncate_str($row_getPosts['entry']),600);

Just don't forget to provide a link for the full article.. for example.

  echo $summary.' <a href="article.php?post='.$row['id'].'">Read More</a>';