How can I limit the character output of a string in PHP?

To limit the character output of a string in PHP, you can use the `substr()` function to extract a portion of the string up to a specified length. This function takes three parameters: the string itself, the starting position (usually 0), and the length of the substring you want to extract.

$string = "This is a long string that needs to be limited in character output.";
$limitedString = substr($string, 0, 20);
echo $limitedString;