从字符串中提取未知数字

Hal*_*jan 0 css php string extract

我有一个字符串"padding: 0px 0px 0px 0px".但数字是未知的,所以可以是0,5,10,25,100或其他...

将每个变量提取到变量的最佳方法是什么?

(i.e. 
$number1 = first number
$number2 = second number
$number3 = third number
$number4 = fourth number)
Run Code Online (Sandbox Code Playgroud)

Chr*_*tof 6

Haljan,

这应该工作:

preg_match_all('/([\d]+)px/', $string, $matches);
var_dump($matches);
Run Code Online (Sandbox Code Playgroud)

它匹配所有后跟"px"的数字并将它们写入$ matches.