This question already has an answer here:
I am using the following PHP code to display a set of ellipses directly after 220 characters have displayed on-screen from the description field in a MySQL database.
...echo "<td>"; echo '<a title="'.$row['title_tag']. '" href="' . $row['hyperlink'] . '">' . substr($row['description'], 0, 220) . " . . ." . '</a>'; echo "</td>";...
It works, but unfortunately this can cut off in the middle of a word. Is there a simple way in the code that I have used above to get it to cut at the next available space or end of word?
</div>
$string = preg_replace("/[^ ]*$/", '', substr($string, 0, $length));
This will cut a string after $length
and then cut it to the end of the last word
Save potentially a load of wasted data being pulled out of your database, change your query to :
SELECT .... LEFT(description, 220) as description WHERE .... etc
Then apply the tricks in previous answers using PHP on the string to only show up to the last space.