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! Link to comment https://forums.phpfreaks.com/topic/191440-truncate-text-variable-and-php-help/ 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 Link to comment https://forums.phpfreaks.com/topic/191440-truncate-text-variable-and-php-help/#findComment-1009322 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); ?> Link to comment https://forums.phpfreaks.com/topic/191440-truncate-text-variable-and-php-help/#findComment-1009818 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? Link to comment https://forums.phpfreaks.com/topic/191440-truncate-text-variable-and-php-help/#findComment-1009822 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.