Home > Article > Backend Development > php rtrim(), substr() delete the last character of a string_PHP tutorial
There is a saying that we use these two functions to delete the last character of a string. rtrim deletes spaces and some special characters by default, but you can also delete specified characters. For substr, we take the character length. Naturally, as long as Just take the character length and subtract one, as shown in the following example.
*/
$str ='abcea';
echo rtrim($str,'a');
//Method 2
echo '
'.substr($str,0,strlen($str)-1);