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.
More Related Contents:
- Extract a single (unsigned) integer from a string
- Find a match pattern of any digit and space with any character in a string and replace with | in PHP [closed]
- Remove new lines from string and replace with one empty space
- How to remove accents and turn letters into “plain” ASCII characters? [duplicate]
- Capturing text between square brackets in PHP
- Remove multiple whitespaces
- Convert a comma-delimited string into array of integers?
- How do I remove all specific characters at the end of a string in PHP?
- How to remove non-alphanumeric characters?
- How to mimic Stack Overflow Auto-Link Behavior
- Converting an integer to a string in PHP
- Remove control characters from PHP string
- How to split a string by multiple delimiters in PHP?
- Converting a number (1, 2, 3) to a string (one, two, three) in PHP
- PHP remove special character from string
- Split camelCase word into words with php preg_match (Regular Expression)
- How to split a long string without breaking words?
- Php – regular expression to check if the string has chinese chars
- PHP – Add link to a URL in a string
- Close open HTML tags in a string
- Regex & PHP – isolate src attribute from img tag
- Remove accents without using iconv
- Remove all non-numeric characters from a string; [^0-9] doesn’t match as expected
- How to prefix a positive number with plus sign in PHP
- Extract floating point numbers from a delimited string in PHP
- How to remove numbers from a string with RegEx
- How to validate that a string only contain lowercase letters?
- Function To Create Regex Matching a Number Range
- Regex to match an IP address [closed]
- How to use RegexIterator in PHP