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
Post a Comment