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.

Read Also:  Laravel Ajax Bootstrap Toggle switch Update MySQL

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 :

Read Also:  queue applications

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. Read Also:  FontSpace Web Application Icons
  2. Read Also:  PHP Laravel Check if Array is empty
  3. Read Also:  Simple Jquery ajax request example with demo
  4. Read Also:  How to add custom jquery image validation?
  5. Read Also:  PHP access Global-Superglobals array Variables
  6. Read Also:  php remove last character from string Code Example
  7. Read Also:  How to Validate Date String in Laravel?
  8. Read Also:  PHP Shorten String Function
  9. Read Also:  PHP Ajax Display Dynamic MySQL Data in Bootstrap Modal
  10. Read Also:  PHP Webcam Capture Image and Save from Camera