$str = "Instant Oats Drink - Chocolate Flavour 165g (33g x 5)";
preg_match('/(?P<title>.*) (?P<grammars>\d+g) \((?P<portion>\d+g) x (?P<times>\d+)\)/', $str, $m);
echo "Title : " . $m['title'] . '<br />';
echo "Grammars : " . $m['grammars'] . '<br />';
echo "Portion : " . $m['portion'] . '<br />';
echo "Times : " . $m['times'] . '<br />';
I really don't know what meaning in preg_match. For example "?P<title>"
, "\d+g"