Are there any built-in PHP functions that can help in removing both the first and last characters of a string simultaneously?

One way to remove both the first and last characters of a string simultaneously in PHP is by using the substr() function. We can use substr() to extract a portion of the string starting from the second character (index 1) up to the second last character. This effectively removes the first and last characters from the original string.

$string = "example";
$trimmedString = substr($string, 1, -1);
echo $trimmedString; // Output: xampl