Return to Snippet

Revision: 62366
at February 19, 2013 21:11 by apphp-snippets


Initial Code
<?php
// method 1 - substr and mb_substr
substr($string, 0, -1);
mb_substr($string, 0, -1);
 
// method 2 - substr_replace
substr_replace($string, '', -1);
 
// method 3 - rtrim
// it trims all specified characters from end of the string
rtrim($string, ".");
?>

Initial URL
http://www.apphp.com/index.php?snippet=php-remove-last-character-from-string

Initial Description
This is a very common PHP question of HOW TO remove last character from string in PHP. Find below some ways how to delete last character from string in PHP.

Initial Title
Remove Last Character from String in PHP

Initial Tags
php

Initial Language
PHP