Remove Last Character from String in PHP


/ Published in: PHP
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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. ?>

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.