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.