_locale_import_tokenize_formula
- Versions
- 4.6 – 7
_locale_import_tokenize_formula($formula)
Backward compatible implementation of token_get_all() for formula parsing
author Gerhard Killesreiter
Parameters
$string A string containing the arithmetic formula
Return value
The PHP version of the formula
Code
includes/locale.inc, line 579
<?php
function _locale_import_tokenize_formula($formula) {
$formula = str_replace(" ", "", $formula);
$tokens = array();
for ($i = 0; $i < strlen($formula); $i++) {
if (is_numeric($formula{$i})) {
$num = $formula{$i};
$j = $i + 1;
while($j < strlen($formula) && is_numeric($formula{$j})) {
$num .= $formula{$j};
$j++;
}
$i = $j - 1;
$tokens[] = $num;
}
elseif ($pos = strpos(" =<>!&|", $formula{$i})) { // We won't have a space
$next = $formula{($i+1)};
switch ($pos) {
case 1:
case 2:
case 3:
case 4:
if ($next == '=') {
$tokens[] = $formula{$i} .'=';
$i++;
}
else {
$tokens[] = $formula{$i};
}
break;
case 5:
if ($next == '&') {
$tokens[] = '&&';
$i++;
}
else {
$tokens[] = $formula{$i};
}
break;
case 6:
if ($next == '|') {
$tokens[] = '||';
$i++;
}
else {
$tokens[] = $formula{$i};
}
break;
}
}
else {
$tokens[] = $formula{$i};
}
}
return $tokens;
}
?>Login or register to post comments 