Remove Last Character from String

Here are 3 methods which can remove the Last Character from String in PHP

<?php
// method 1 – substr and mb_substr
substr($string, 0, -1);
mb_substr($string, 0, -1);

// method 2 – substr_replace
substr_replace($string, ”, -1);

// method 3 – rtrim
// it trims all specified characters from end of the string
rtrim($string, “.”);
?>

LEAVE A REPLY

Please enter your comment!
Please enter your name here

*