PHP: Remove last Character from String
Question by Guest | 2015-06-26 at 13:33
Currently, I am searching for a possibility to cut off the last character from a string using PHP.
This action should be carried out independent from the character that stands at the end of the string. In other words, any arbitrary character should be removed from the end.
Is PHP providing any function for this? Thank you very much.
Related Topics
MySQL: Line Breaks in MySQL
Tip | 0 Comments
PHP: Remove arbitrary Characters at the Beginning and the End of a String
Tutorial | 0 Comments
JavaScript: Remove last character from string
Tip | 5 Comments
PHP: Check Strings with Ctype-Functions for Character Classes
Article | 0 Comments
PHP: Remove all empty elements from string array
Tip | 0 Comments
PHP: Get first Digit of Number or String
Tutorial | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
You can use the PHP function substr() for this purpose.
In order to remove the last character from the string, you have to pass 0 as first parameter and -1 as second parameter.
The second parameter is specifying from which character position the string should be copied. The first character is the character 0 and because we do not want to remove anything from the front, we are accordingly using 0 as the second parameter.
The third parameter is specifying the length of the substring. A negative value means that it is counted from behind. That is why we are passing -1 to get the last character.
2015-06-27 at 10:31