Home Ask Login Register

Developers Planet

Your answer is one click away!

subhra February 2016

How to get last charcter after underscore of a string using PHP

I need one small help. I need to echo the characters of a string which are after _ using PHP. Have a look at the example below.

$arr = "abcdef_123";

From the above example I need 123 which should be stored in another variable.

Please help me.


Mr. Engineer February 2016

Try this code :

echo end(explode("_",$arr));

AnkiiG February 2016

Try as below :

$arr = 'abcdef_123';
$res = explode("_",$arr);
echo $res[1];

Post Status

Asked in February 2016
Viewed 3,599 times
Voted 7
Answered 2 times


Leave an answer

Quote of the day: live life