xxxxxxxxxx
//Remove the last character using substr
$string = substr($string, 0, -1);
xxxxxxxxxx
<?php
$string = "hello world";
// create a substring starting 1 character from
// the beginning and ending 1 character from the end
$trimmed = substr($string, 1, -1);
echo $trimmed; // prints "ello worl"
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