php remove last char from string
//Remove the last character using substr
$string = substr($string, 0, -1);
php remove last char from string
//Remove the last character using substr
$string = substr($string, 0, -1);
php substr remove last 4 characters
echo substr($string, 0, -3);
remove last character from string in php
$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
Remove the Last Character From a String in PHP
phpCopy<?php
$mystring = "This is a PHP program.";
echo("This is the string before removal: $mystringn");
$newstring = rtrim($mystring, ". ");
echo("This is the string after removal: $newstring");
?>
Get the Last Character of a String in PHP
phpCopy<?php
$string = "This is a string";
$lastCharPosition = strlen($string) - 1;
for ($x = $lastCharPosition; $x < strlen($string); $x++) {
$newString = $string[$x];
}
echo "The last char of the string is $newString.";
?>
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us