function recipe_unit_from_name in Recipe 5
Same name and namespace in other branches
- 6 recipe.module \recipe_unit_from_name()
Returns information about a unit based on a unit abbreviation or name
1 call to recipe_unit_from_name()
- recipe_parse_ingredient_string in ./
recipe.module - Converts an ingredients name string to an ingredient object
File
- ./
recipe.module, line 990 - recipe.module - share recipes for drupal 5.x
Code
function recipe_unit_from_name($name) {
if (strlen($name) > 1) {
$string = strtolower($name);
}
else {
$string = $name;
}
$ending = substr($string, -1, 1);
if ($ending == 's' && $string != 'ds' || $ending == '.') {
$string = substr($string, 0, strlen($string) - 1);
}
$ending = substr($string, -1, 1);
if ($ending == 's' && $string != 'ds' || $ending == '.') {
$string = substr($string, 0, strlen($string) - 1);
}
static $units_array;
if (!$units_array) {
$rs = db_query('SELECT id,name,abbreviation FROM {recipe_unit}');
while ($unit = db_fetch_object($rs)) {
$units_array[strtolower($unit->name)] = $unit;
$units_array[$unit->abbreviation] = $unit;
}
}
return $units_array[$string];
}