Remove Last Character from String in PHP

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.

[View All Snippets]
Show Plain Text »
  1. <?php
  2. // method 1 - substr and mb_substr
  3. substr($string, 0, -1);
  4. mb_substr($string, 0, -1);
  6. // method 2 - substr_replace
  7. substr_replace($string, '', -1);
  9. // method 3 - rtrim
  10. // it trims all specified characters from end of the string
  11. rtrim($string, ".");
  12. ?>
Create Your Free Account
Please remember that this information is essential to use our services correctly.
After creating the account you will be able to download all of our FREE products.
Fields marked with * are mandatory

Please send me information about updates, new products, specials and discounts from ApPHP!
We recommend that your password should be at least 6 characters long and should be different from your username/email. Please use only letters of the English alphabet to enter your name.

Your e-mail address must be valid. We use e-mail for communication purposes (order notifications, etc). Therefore, it is essential to provide a valid e-mail address to be able to use our services correctly.

All your private data is confidential. We will never sell, exchange or market it in any way. Please refer to Privacy Policy.

By clicking "Create Account", you are indicating that you have read and agree to the ApPHP Terms & Conditions.

Quick Registration with: Facebook / Google