/** * Find element by type: MNEM, UNIT, DATA, DESC * @param string $type * @param string $str * @param bool $trim * @return string */ function getLASElement($type, $str, $trim) { switch ($type) { case 'MNEM': $str = substr($str, 0, strpos($str, '.')); break; case 'UNIT': $str = substr($str, strpos($str, '.') + 1, strpos($str, ' ') - strpos($str, '.') + 1); break; case 'DATA': // hook for "FLD " if (getLASElement('MNEM', $str) == 'FLD ') { $str = substr($str, strpos($str, ' ') + 3, strpos($str, ':') - strpos($str, ' ') - 2); } $str = substr($str, strpos($str, ' ') + 1, strpos($str, ':') - strpos($str, ' ') - 1); break; case 'DESC': $str = substr($str, strpos($str, ':') + 1); break; default: $str = null; break; } return $trim ? trim($str) : $str; }
/** * Init translit and set result in array * @param array &$arr * @param string $fields * @return nothing */ function translit(&$arr, $fields) { $i = 0; foreach ($arr as $key => $value) { if ($i == count($fields)) { break; } if (in_array(getLASElement('MNEM', $value), $fields)) { $i++; $data = getLASElement('DATA', $value); $arr[$key] = getLASElement('MNEM', $value) . '.' . getLASElement('UNIT', $value) . ' ' . parseToTranslit($data) . ':' . getLASElement('DESC', $value); //."\n"; } } }