|
|
@@ -693,6 +693,21 @@ EOF';
|
|
|
return $ret;
|
|
|
}, "");
|
|
|
}
|
|
|
+ static function fixUtf8ToHtmlChars($input) {
|
|
|
+ $input = self::stripInvalidXmlChars($input);
|
|
|
+ $input = self::fixUtf8ToHtmlChar($input, 'µ', 'µ');
|
|
|
+ $input = self::fixUtf8ToHtmlChar($input, 'φ', 'φ');
|
|
|
+ $input = self::fixUtf8ToHtmlChar($input, 'Φ', 'Φ');
|
|
|
+ $input = self::fixUtf8ToHtmlChar($input, '–', '-');
|
|
|
+ //$input = $this->fixUtf8ToHtmlChar($input, '°', '°');// ° is ok in latin2
|
|
|
+ return $input;
|
|
|
+ }
|
|
|
+ static function fixUtf8ToHtmlChar($input, $from, $to) {
|
|
|
+ if (function_exists('mb_split') && false !== ($pos = mb_strpos($input, $from, 0, 'utf-8'))) {
|
|
|
+ return implode($to, mb_split($from, $input));
|
|
|
+ }
|
|
|
+ return $input;
|
|
|
+ }
|
|
|
|
|
|
static function deleteWholeDirectory($dir, $returnFiles = false, $doDelete = true) {
|
|
|
if (!is_dir($dir)) throw new Exception("{$dir} must be a directory");
|
|
|
@@ -729,7 +744,7 @@ EOF';
|
|
|
return (false === $ret) ? [] : $ret;
|
|
|
}
|
|
|
|
|
|
- static function tryHandleException($handler, $callback, $args) { // try again on exception
|
|
|
+ static function tryHandleException(callable $handler, callable $callback, array $args = []) { // try again on exception
|
|
|
try {
|
|
|
return call_user_func_array($callback, $args);
|
|
|
} catch (Exception $e) {
|
|
|
@@ -740,4 +755,13 @@ EOF';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // @param $callback must return bool
|
|
|
+ function arrayFindFirst(array $input, callable $callback) { // @return found index or -1 if not found
|
|
|
+ $idx = -1;
|
|
|
+ foreach ($input as $idx => $item) {
|
|
|
+ if ($callback($item)) return $idx;
|
|
|
+ }
|
|
|
+ return $idx;
|
|
|
+ }
|
|
|
+
|
|
|
}
|