I try to read chemical formulas like C6H12-1, C6H12-1(co2) using
"/(?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));
It prints C6-H5(CH3) 15.0 ! ( ) as output, but i only want to read C6-H5(CH3) how can i eliminate data after space ie 15.0 ! ( )
I tried to use $ but i failed. I am working on php for first time.
Apologize if my question is silly
i use preg_match_all instead of preg_replace and list chemical formula's
$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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.