What is the best way to remove the last character of a string in PHP?

To remove the last character of a string in PHP, you can use the `substr()` function to extract a substring of the original string without the last character. The `substr()` function takes the original string, a starting index of 0, and a length that is the length of the original string minus 1. This will effectively remove the last character from the string.

$string = "Hello World";
$trimmedString = substr($string, 0, -1);
echo $trimmedString;