PHP Get Last 3 Characters from String Example
Hi Dev,
In this tutorial, you will learn php get last 3 Characters from string example. This tutorial will give you simple example of how to get last three Characters from string in php?. we will help you to give example of get last three Characters from string in php example. This article goes in detailed on how to use function to get last three Characters from string in php?.
There are two example to get Last 3 Characters from strings in PHP. in this example, we will use to substr() and mb_substr() function to get Last 3 Characters. so Let's both the following example with output.
Example 1: Get Last 3 Characters from String
index.php
<?php
$str = "Hello World";
//Get Last Three Characters from a String
$result = substr($str, strlen($str)-3);
echo $result;
?>
Output:
rld
Example 2: Get Last 3 Characters from String
index.php
<?php
$str = "Nicesnippets";
//Get Last Three Characters from a String
$result = mb_substr($str, -3);
echo $result;
?>
Output:
ets
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