Get last whole number in a string

you could do:

$text = "1 out of 23";
if(preg_match_all('/\d+/', $text, $numbers))
    $lastnum = end($numbers[0]);

Note that $numbers[0] contains array of strings that matched full pattern,
and $numbers[1] contains array of strings enclosed by tags.

Leave a Comment