1//Remove the last character using substr
2$string = substr($string, 0, -1);
1$arrStr = 'Str1, Str2, str3, ';
2echo rtrim($arrStr, ", "); //Str1, Str2, str3
3echo substr_replace($arrStr, "", -2); //Str1, Str2, str3
4echo substr($arrStr, 0, -2); // Str1, Str2, str3
1phpCopy<?php
2$mystring = "This is a PHP program.";
3echo("This is the string before removal: $mystring\n");
4$newstring = rtrim($mystring, ". ");
5echo("This is the string after removal: $newstring");
6?>
7