How can PHP be used to limit the length of text displayed in an HTML table?

To limit the length of text displayed in an HTML table using PHP, you can use the `substr` function to truncate the text to a specified length. This can be useful when you have long text data in a table column and want to display only a certain number of characters.

<?php
$text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
$limit = 20; // Set the character limit here

if (strlen($text) > $limit) {
    $text = substr($text, 0, $limit) . "..."; // Truncate the text if it exceeds the limit
}

echo $text; // Output the truncated text
?>