Posted By

apphp-snippets on 02/19/13


Tagged

php character strings last


Versions (?)

Remove Last Character from String in PHP


 / Published in: PHP
 

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

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.

  1. <?php
  2. // method 1 - substr and mb_substr
  3. substr($string, 0, -1);
  4. mb_substr($string, 0, -1);
  5.  
  6. // method 2 - substr_replace
  7. substr_replace($string, '', -1);
  8.  
  9. // method 3 - rtrim
  10. // it trims all specified characters from end of the string
  11. rtrim($string, ".");
  12. ?>

Report this snippet  

You need to login to post a comment.