diff --git a/inc/fulltext.php b/inc/fulltext.php index eab8850dcc22cd1d645dd66e0f953be223306b42..7ee3860636b89bd645e214d6bd8bb3c1c4df371b 100644 --- a/inc/fulltext.php +++ b/inc/fulltext.php @@ -394,10 +394,17 @@ function ft_snippet_re_preprocess($term) { return $term; } - // unicode word boundaries - // see http://stackoverflow.com/a/2449017/172068 - $BL = '(?<!\pL)'; - $BR = '(?!\pL)'; + if (UTF8_PROPERTYSUPPORT) { + // unicode word boundaries + // see http://stackoverflow.com/a/2449017/172068 + $BL = '(?<!\pL)'; + $BR = '(?!\pL)'; + } else { + // not as correct as above, but at least won't break + $BL = '\b'; + $BR = '\b'; + } + if(substr($term,0,2) == '\\*'){ $term = substr($term,2); diff --git a/inc/infoutils.php b/inc/infoutils.php index 0dc7092ad5bb415bd1151099497c86ebcf33a94f..a9c33acfd1d2c93f1828d1fa240acb01ada25d1c 100644 --- a/inc/infoutils.php +++ b/inc/infoutils.php @@ -176,10 +176,10 @@ function check(){ msg('mb_string extension not available - PHP only replacements will be used',0); } - if (!preg_match("/^.$/u", "ñ")) { + if (!UTF8_PREGSUPPORT) { msg('PHP is missing UTF-8 support in Perl-Compatible Regular Expressions (PCRE)', -1); } - if (!preg_match("/^\pL$/u", "ñ")) { + if (!UTF8_PROPERTYSUPPORT) { msg('PHP is missing Unicode properties support in Perl-Compatible Regular Expressions (PCRE)', -1); } diff --git a/inc/utf8.php b/inc/utf8.php index 6fab8502c204f23427c79fe9bc78fb3b727f3934..c944667f74448525b48e0a602547369c127ab505 100644 --- a/inc/utf8.php +++ b/inc/utf8.php @@ -17,6 +17,25 @@ if(!defined('UTF8_MBSTRING')){ } } +/** + * Check if PREG was compiled with UTF-8 support + * + * Without this many of the functions below will not work, so this is a minimal requirement + */ +if(!defined('UTF8_PREGSUPPORT')){ + define('UTF8_PREGSUPPORT', (bool) @preg_match('/^.$/u', 'ñ')); +} + +/** + * Check if PREG was compiled with Unicode Property support + * + * This is not required for the functions below, but might be needed in a UTF-8 aware application + */ +if(!defined('UTF8_PROPERTYSUPPORT')){ + define('UTF8_PROPERTYSUPPORT', (bool) @preg_match('/^\pL$/u', 'ñ')); +} + + if(UTF8_MBSTRING){ mb_internal_encoding('UTF-8'); } if(!function_exists('utf8_isASCII')){