What function in PHP can be used to shorten a text to a specific number of characters?

To shorten a text to a specific number of characters in PHP, you can use the `substr()` function. This function takes three parameters: the string to be shortened, the starting position (usually 0), and the length of the substring you want to extract. By specifying the desired length, you can easily truncate the text to the desired number of characters.

$text = "This is a long text that needs to be shortened.";
$shortened_text = substr($text, 0, 20);
echo $shortened_text; // Output: "This is a long text"