1

I have this code, I need to limit the word in the field "newsContenuto" and add some"..." .

echo "<tr>";
        echo "<td>{$newsID}</td>";
        echo "<td>{$newsData}</td>";
        echo "<td>{$newsAutore}</td>";
        echo "<td>{$newsTitolo}</td>";
        echo "<td>{$newsContenuto}</td>";
        echo "<td>";
Dharman
  • 30,962
  • 25
  • 85
  • 135
Myself
  • 11
  • 1
  • https://www.php.net/manual/en/function.substr.php can help – brombeer Oct 02 '19 at 07:53
  • If you want to make sure you only break on a space character (so don't have something like `hel...`), this could help https://stackoverflow.com/questions/52114612/php-make-an-excerpt-by-cutting-the-string-on-the-last-space-after-x-characters/52115331#52115331 – Nick Oct 02 '19 at 08:03

1 Answers1

3

Try this example:

echo "<td>" . substr( $newsContenuto, 0, 20 ) . "...</td>";

In the above code, I've set 20, you can increase that.

Soroush Chehresa
  • 5,490
  • 1
  • 14
  • 29