What is the function in PHP that can be used to shorten a string to a specific number of characters?

To shorten a string to a specific number of characters in PHP, you can use the `substr()` function. This function allows you to extract a substring from a string starting at a specified position and with a specified length. By using `substr()`, you can easily truncate a string to the desired length.

$string = "This is a long string that needs to be shortened.";
$shortenedString = substr($string, 0, 20); // Shorten the string to 20 characters

echo $shortenedString; // Output: "This is a long stri"