考虑以下值:
$format = ',0'; // Thousand separators ON, no decimal places
$format = '0'; // Thousand separators OFF, no decimal places
$format = '0.000'; // Thousand separators OFF, 3 decimal places
$format = ',0.0'; // Thousand separators ON, 1 decimal place
- 首先要做的是查看是否
$format
以','为前缀。这告诉我启用了千位分隔符。 - 其次,我必须查看第一个零之后有多少个零。例如,以下将是小数点后 2 位“0.00”等。
我已经设法匹配表达式(这不是很难),但我想做的是提取单个匹配项,这样我就可以知道是否找到了“,”以及有多少个零等。 ..
这是我到目前为止所拥有的:
preg_match_all('/^\,?[0]?[\.]?([0])+?$/',$value['Field_Format'],$matches);