I have a string like "padding: 0px 0px 0px 0px"
. The digits are however unknown so the can be 0, 5, 10, 25, 100 or whatever...
What's the best way to extract each of those to a variable?
(i.e.
$number1 = first number
$number2 = second number
$number3 = third number
$number4 = fourth number)
Haljan,
This should work:
preg_match_all('/([\d]+)px/', $string, $matches);
var_dump($matches);
It matches all numbers that are followed by a "px" and writes them to $matches.
If You want to extract unknown digit from a string them you may use this:
$new_string_without_digit = preg_replace("/[0-9]/", '', $your_string);