fishfood Posted February 9, 2010 Share Posted February 9, 2010 I am just learning PHP and I am struggling to get this to work... <?php function myTruncate($string, $limit, $break=" ", $pad="...") { if(strlen($string) <= $limit) return $string; $string = substr($string, 0, $limit); if(false !== ($breakpoint = strrpos($string, $break))) { $string = substr($string, 0, $breakpoint); } return $string . $pad; } $description = "This is where the text string lies."; $shortdesc = myTruncate($description, 100); echo "<p>$shortdesc</p>"; ?> In here: $description = "This is where the text string lies."; How could I put this: <?php echo nl2br($row_myData['content']); ?> so that the recordset content will show up as the description variable? Thanks! Quote Link to comment Share on other sites More sharing options...
RussellReal Posted February 9, 2010 Share Posted February 9, 2010 not exactly sure what you mean.. but tryna guess here.. $description = nl2br($row_myData['content']); // lol Quote Link to comment Share on other sites More sharing options...
fishfood Posted February 10, 2010 Author Share Posted February 10, 2010 I've solved it. Incase anyone wants to know, it's: <?php echo myTruncate(nl2br($row_myData['content']), 100); ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 10, 2010 Share Posted February 10, 2010 what are you on about please... Was you asking in a strange way, how to have a brake every 100 character, or word? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.