我正在尝试从字符串示例中提取一些度量大小:
例子:
$s1=" foobar 10mm bar" // 10mm
$s2=" foobar 10-300ml barbr" // 10-300ml
$s3=" foobar 25 - 70 cm foo" // 25-70cmm
我该怎么做?
我试过这样:
$sizes_volume_distance_markers = array('mm','ml','l','cm');
static $pattern_final_voldist;
if(!$pattern_final_voldist)
{
$pattern_final_voldist = implode("|",self::$sizes_volume_distance_markers);
}
if(preg_match_all("/([\d.-]{1,4}[\s.-]{0,2}($pattern_final_voldist) {1,2})+/i",$str,$vvalues))
{
var_dump($vvalues);
}