Jump to content

Truncate text - Variable and PHP Help


fishfood

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.