I have this string #22aantal283xuitvoeren
.
What is the best way to find the last numeric value in a string? (283 in this case)
I don't think chop()
or substr()
is the wat to go.
I have this string #22aantal283xuitvoeren
.
What is the best way to find the last numeric value in a string? (283 in this case)
I don't think chop()
or substr()
is the wat to go.
You can use preg_match_all and match all digits.
Then the last item in the array is the last number in the string.
$s = "#22aantal283xuitvoeren";
preg_match_all("/\d+/", $s, $number);
echo end($number[0]); // 283