Reputation: 1301
$text = "About 5,590 results";
preg_match("/of about <b>(.*?)</", $text, $matches);
it return the 5590 but when I tried with :
$text = "4 results";
preg_match("/of about <b>(.*?)</", $text, $matches);
is there any pattern for this case? I want to get "4" from "4 results"
Upvotes: 0
Views: 136
Reputation: 22172
If you just need the numbers, you can use this regex:
$regex = "/\d+[\.,]?\d*/";
This will match numbers in the following formats:
Upvotes: 5