Remove Last Character from String in PHP

Today, We want to share with you Remove Last Character from String in PHP.In this post we will show you How to eliminate/remove last character from a string in php, hear for How to remove last comma from string using php we will give you demo and example for implement.In this post, we will learn about Strip whitespace (or other characters) from the end of a string with an example.

Remove Last Character from String in PHP

There are the Following The simple About Remove Last Character from String in PHP Full Information With Example and source code.

As I will cover this Post with live Working example to develop remove character from string php, so the remove last character from string php for this example is following below.

Example 1 – substr_replace function

Use the substr_replace function in PHP

$string = "Welcome PakaInfo!";
echo "Source string: " . $string . "\n";

echo "Results string: " . substr_replace($string ,"",-1) . "\n";

Output
Source string: Welcome PakaInfo!
Results string: Welcome PakaInfo

Example 2 – substr function

Use the substr function in PHP

$string = "Welcome PakaInfo!";
echo "Source string: " . $string . "\n";

echo "Results string: " . substr($string, 0, -1) . "\n";

Output
Source string: Welcome PakaInfo!
Results string: Welcome PakaInfo

Example 3 – mb_substr function

mb_substr function to remove characters in PHP

$string = "Welcome PakaInfo!";
echo "Source string: " . $string . "\n";

echo "Results string: " . mb_substr($string, 0, -1) . "\n";

Output
Source string: Welcome PakaInfo!
Results string: Welcome PakaInfo

Example 4 – rtrim function

PHP rtrim function to used to remove specific characters

$string = "Welcome PakaInfo!";
echo "Source string: " . $string . "\n";

echo "Results string: " . rtrim($string, "!") . "\n";

Output
Source string: Welcome PakaInfo!
Results string: Welcome PakaInfo

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Remove Last Character from String in PHP.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1.   Laravel 6 Image Uploader and Browser for CKEditor
  2.   PHP cUrl GET & POST Methods Example
  3.   VueJS Convert Comma separated String To Array Example
  4.   PHP Dynamically QR Codes Generator Scannable Barcodes
  5.   Setup Laravel 6 Login Authentication
  6.   Display JSON Data from database using php using jquery ajax
  7.   Creating Custom Database Tables plugin or theme using WordPress
  8.   Laravel Eloquent Replicate Table Row
  9.   MongoDB CRUD Tutorial With Example From Scratch
  10.   how to get last inserted record in laravel?