我有一个像 "padding: 0px 0px 0px 0px"
这样的字符串。
然而,这些数字是未知的,因此可以是 0、5、10、25、100 或其他任何...
将每个变量提取到变量的最佳方法是什么?
(i.e.
$number1 = first number
$number2 = second number
$number3 = third number
$number4 = fourth number)
最佳答案
哈尔扬
这应该有效:
preg_match_all('/([\d]+)px/', $string, $matches);
var_dump($matches);
它匹配所有后跟“px”的数字并将它们写入 $matches。
关于php - 从字符串中提取未知数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5744450/