To remove the last three characters from a string, we can use the
substr() function by passing the
length as arguments.
Here is an example, that removes the last three characters from a given string.
$name="John res"; //if length is negative it starts removing from the end $result = substr($name,0,-3); echo $result;
The substr() function doesn’t mutate the original string, instead of it creates a new string the modified data.