PHP Get Last 10 Characters from String Example

03-Apr-2023

.

Admin

PHP Get Last 10 Characters from String Example

Hi Dev,

This tutorial shows you php get last 10 Characters from string example. let’s discuss about get last ten Characters from string in php example. In this article, we will implement a last ten Characters get from string in php. you'll learn how to get last ten Characters from string in php?.

There are two example to get Last 10 Characters from string in PHP. in this example, we will use to substr() and mb_substr() function to get Last 10 Characters. so Let's both the following example with output.

Example 1: Get Last 10 Characters from String


index.php

<?php

$str = "Hello Developers";

//Get Last Ten Characters from a string

$result = substr($str, strlen($str)-10);

echo $result;

?>

Output:

Developers

Example 2: Get Last 10 Characters from String

index.php

<?php

$str = "Welcome to Nicesnippets.com";

//Get Last Ten Characters from a string

$result = mb_substr($str, -10);

echo $result;

?>

Output:

ippets.com

I hope it could help you...

#PHP