PHP String Remove Last Character Example
Hi Dev,
In this example, you will learn php string remove last character example. we will help you to give example of how to remove last character from string in php?. it's simple example of php remove last character from string. I explained simply about string remove last character php example.
There are four ways to remove last character from string in php. in this example, we will use to rtrim() function, substr_replace(), mb_substr(), substr() function remove last character from string.Let's see all examples with output.
Example 1:
index.php
<?php
$str = "Hello World!";
// Remove Last Character from String
$result = rtrim($str, "!");
echo $result;
?>
Output:
Hello World
Example 2:
index.php
<?php
$str = "Nicesnippets.com?";
// Remove Last Character from String
$result = substr_replace($str ,"",-1);
echo $result;
?>
Output:
Nicesnippets.com
Example 3:
index.php
<?php
$str = "Mywebtuts.com>";
// Remove Last Character from String
$result = mb_substr($str, 0, -1);
echo $result;
?>
Output:
Mywebtuts.com
Example 4:
index.php
<?php
$str = "Hello Jaydeep?";
// Remove Last Character from String
$result = substr($str, 0, -1);
echo $result;
?>
Output:
Hello Jaydeep
I hope it could help you...
- How To Use Php Conditional Statement Example
- How to Check if String Contains Regex in PHP?
- PHP Array_column() Function Example
- PHP Generate List of Random Numbers Between 0 and 100 Example
- How to User Login with Facebook in PHP?
- How to Explode Every Character into Array Using PHP Example?
- PHP Form Validation Tutorial
- PHP Convert XML to JSON Example