27 static function textMatch($haystack, $needle, $collation, $matchType =
'contains') {
31 case 'i;ascii-casemap' :
34 $haystack = str_replace(range(
'a',
'z'), range(
'A',
'Z'), $haystack);
35 $needle = str_replace(range(
'a',
'z'), range(
'A',
'Z'), $needle);
42 case 'i;unicode-casemap' :
43 $haystack = mb_strtoupper($haystack,
'UTF-8');
44 $needle = mb_strtoupper($needle,
'UTF-8');
48 throw new Exception\BadRequest(
'Collation type: ' . $collation .
' is not supported');
55 return strpos($haystack, $needle) !==
false;
57 return $haystack === $needle;
59 return strpos($haystack, $needle) === 0;
61 return strrpos($haystack, $needle) === strlen($haystack) - strlen($needle);
63 throw new Exception\BadRequest(
'Match-type: ' . $matchType .
' is not supported');
81 $encoding = mb_detect_encoding(
$input, [
'UTF-8',
'ISO-8859-1'],
true);
83 if ($encoding ===
'ISO-8859-1') {
84 return utf8_encode(
$input);
static ensureUTF8($input)
This method takes an input string, checks if it's not valid UTF-8 and attempts to convert it to UTF-8...
static textMatch($haystack, $needle, $collation, $matchType='contains')
Checks if a needle occurs in a haystack ;)