user1578707 user1578707 - 16 days ago 7
PHP Question

PHP Explode() get strings after the last PERIOD (.)

i hope someone can help me.

I have this string for example:

But the LORD is in His holy temple. Let all the earth be silent before Him. Habakkuk 2:20


I want to use explode function to get the last part string "Habakkuk 2:20", my problem is how to tell to explode function to choose the last period (.) of the string?

Answer

Not sure why you need explode here. You can find the position of the last period using the strrpos function and get everything after that pos:

$str = 'But the LORD is in His holy temple. Let all the earth be silent before Him. Habakkuk 2:20';
$pos = strrpos($str, '.');
echo substr($str, $pos+1);