function readIngredientLine($line) { $contLastLine = false; /* * Extract the three parts of a ingredient (name, amount, measurement) * into separate strings. They are separated according to their length: * amount: columns 0-6 * measurement: columns 8-9 * name: columns 11+ */ $amount = substr($line, 0, 7); // col 0-6 $measurement = substr($line, 8, 2); // col 8-9 $name = substr($line, 11); // col 11+ $amount = trim($amount); $measurement = trim($measurement); $name = trim($name); if (intval($amount) == 0) { $amount = $amount; } else { $amount = Fraction::strToFloat($amount); } if ($name != "" && $name[0] == '-' && $name[1] != '-') { // continue previous ingredient line. $contLastLine = true; trim($name); $name = trim(preg_replace("/^-+/", " ", $name)); // remove all leading "-" chars $this->currentIngredient->name = htmlspecialchars($name, ENT_QUOTES); // print "readIngredientLine: Extra matches: $name <br />\n"; } else { // just an ordinary ingredient line $this->currentIngredient->quantity = $amount; $this->setUnit($measurement); $this->currentIngredient->name = htmlspecialchars($name, ENT_QUOTES); // print "readIngredientLine: Ingredient: $name <br />\n"; } return $contLastLine; }