xxxxxxxxxx
$str = removeLast3char($str);
function removeLast3char($string){
return trim(substr($string, 0, -3));
}
xxxxxxxxxx
//Remove the last character using substr
$string = substr($string, 0, -1);
xxxxxxxxxx
phpCopy<?php
$mystring = "This is a PHP program.";
echo substr($mystring, 0, -1);
?>
xxxxxxxxxx
$arrStr = 'Str1, Str2, str3, ';
echo rtrim($arrStr, ", "); //Str1, Str2, str3
echo substr_replace($arrStr, "", -2); //Str1, Str2, str3
echo substr($arrStr, 0, -2); // Str1, Str2, str3