PHP: Last n characters to a specified character in a string? -


i want last n characters string, after last "-" character. like:

$string = "something-123"; $substring = 123; $string2 = "something-253672-something-21"; $substring2 = 21; 

these characters can numbers. how can php? (sorry bad english)

you explode string , parse last element of resulting array:

$splitted = explode("-", $string); $numbers = end($splitted);  if (is_numeric($numbers)) {     echo "yay!"; } else {     echo "nay!"; } 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -