Here is an example string:
“60 reviews from 12 people, 20% of users”
(Let’s call it $v)
I have been using preg_match_all to get an array with all the numbers
$pattern = '!\d+!';
preg_match_all($pattern, $v, $matches, PREG_SET_ORDER);
The result I get is:
Array
(
[0] => Array
(
[0] => 60
)
[1] => Array
(
[0] => 12
)
[2] => Array
(
[0] => 20
)
)
But despite trying for some time I haven’t been able to get what I want. What I want is this:
Array
(
[0] => 60
[1] => 12
[2] => 20
)
Maybe should I be using preg_match instead? but with preg_match I only get one value… Or maybe along with a loop? It looks like an ugly hack… There should be a profesional way out there… Thanks in advance to PHP experts! 😉
Presuming the format always stays the same, you can do the following:
This will output: