What PHP function can be used to limit the length of a string retrieved from a database?

When retrieving a string from a database, you may want to limit the length of the string to a certain number of characters to prevent displaying excessively long content. One way to achieve this is by using the `substr()` function in PHP, which allows you to extract a substring from a string based on a specified start position and length.

// Retrieve the string from the database
$fullString = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";

// Limit the length of the string to 20 characters
$limitedString = substr($fullString, 0, 20);

// Output the limited string
echo $limitedString;