Answered by : kasmin
//Remove the last character using substr
$string = substr($string, 0, -1);
Source : | Last Update : Thu, 09 Apr 20
Answered by : vast-vulture-6ly95kdzpzxf
<?php
echo substr('abcdef',0, -1); // abcde
?>
Source : | Last Update : Tue, 16 Jun 20
Answered by : code-grepper
$hell = substr('hello', 0, -1);
Source : | Last Update : Mon, 11 Nov 19
Answered by : helpful-hippopotamus-7rhwx737yf34
echo substr($string, 0, -3);
Source : https://stackoverflow.com/questions/4915753/how-can-i-remove-3-characters-at-the-end-of-a-string-in-php | Last Update : Sat, 31 Oct 20
Answered by : manoj-kumar
$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
Source : | Last Update : Tue, 09 Feb 21
Answered by : pawan-mall
phpCopy<?php
$mystring = "This is a PHP program.";
echo substr($mystring, 0, -1);
?>
Source : https://www.delftstack.com/howto/php/php-remove-last-character-from-string/ | Last Update : Fri, 30 Apr 21
Answered by : moin-ahmed
$newarraynama = rtrim($arraynama, ", ");
Source : https://stackoverflow.com/questions/5592994/remove-the-last-character-from-a-string | Last Update : Sat, 01 May 21
Answered by : tough-teira-jbi7oxbw9kdg
$newarraynama = rtrim($arraynama, ", ");
Source : https://stackoverflow.com/questions/5592994/remove-the-last-character-from-a-string | Last Update : Thu, 30 Sep 21
Answered by : pawan-mall
phpCopy<?php
$mystring = "This is a PHP program.";
echo("This is the string before removal: $mystring\n");
$newstring = rtrim($mystring, ". ");
echo("This is the string after removal: $newstring");
?>
Source : https://www.delftstack.com/howto/php/php-remove-last-character-from-string/ | Last Update : Fri, 30 Apr 21
Answered by : rohit-ghodadra
$str = removeLast3char($str);
function removeLast3char($string){ return trim(substr($string, 0, -3));
}
Source : | Last Update : Wed, 23 Mar 22