我尝试使用
读取C6H12-1,C6H12-1(co2)等化学式"/(?i)\b[a-z]+(?:\d+[a-z]+)*\b/"
$fuel_value = preg_replace("/(?i)\b[a-z]+(?:\d+[a-z]+)*\b/","",$fuel);
print_r(implode($fuel_value));
打印C6-H5(CH3)15.0! ()作为输出,但我只想读取C6-H5(CH3)如何消除空间后的数据,即15.0! ()
我试图使用$但是我失败了。我是第一次使用php。
如果我的问题很愚蠢,请道歉
答案 0 :(得分:0)
答案 1 :(得分:0)
我使用preg_match_all而不是preg_replace并列出化学公式的
$str = "FUEL C6H12-1 0.0 ! Fuel Fraction oFUEL C6H12-1 0.0 ! Fuel Fraction of Total Fuel Species(molefr) FUEL C6H5CH3 15.0 ! Fuel Fraction of Total Fuel Species(molefr) FUEL IC8H18 72.5 ! Fuel Fraction of Total Fuel Species(molefr) FUEL NC7H16 12.5 ! Fuel Fraction of Total Fuel Species (molefr) FUEL T124MBZ 0.0 ! Fuel Fraction of Total Fuel Species (molefr)";
preg_match_all("/[A-Z]+\d.*?[\s]/",$str,$match);
print_r($match);