w3resource
php Programming Exercies

PHP String Exercises: Get the last three characters of a string

PHP String: Exercise-7 with Solution

Write a PHP script to get the last three characters of a string.

Sample String : '[email protected]'

Pictorial Presentation:

PHP String Exercises: Get the last three characters of a string

Sample Solution:

PHP Code:

<?php
$str1 = '[email protected]';
echo substr($str1, -3)."\n";
?>

Sample Output:

com

Flowchart:

Flowchart: Get the last three characters of a string

PHP Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a PHP script to extract the user name from the specified email ID.
Next: Write a PHP script to format values in currency style.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming