PHP Get Last 3 Characters from String Example

03-Apr-2023

.

Admin

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...

#PHP