Правила на сайта
0 Потребители и 1 Гост преглежда(т) тази тема.
If you try to find the offset when searching in UTF-8 string (containing multibyte characters, like cyrillic characters) with preg_match, using the PREG_OFFSET_CAPTURE flag, you may have different result from what you expected.First of all you must compiled PHP with Multibyte Support (mbstring). Then you must configure to use Multibyte Support functions (mb_*) or turn on some php Runtime Configurations (php.ini, apache vhost conf file, .htaccess or somewhere else): php_value default_charset UTF-8 php_value mbstring.func_overload 7 php_value mbstring.internal_encoding UTF-8 php_value mbstring.detect_order UTF-8When using preg_match with PREG_OFFSET_CAPTURE flag and UTF-8 string the function will count bytes and NOT characters, so 2 bytes but NOT 1 character for some multibyte character. That's way the offset will be more than what you expected.My simple solution is using mb_strpos: ... preg_match($pattern, $found_text, $matches, PREG_OFFSET_CAPTURE); // This will convert $matches[0][1] multibyte byte length to multibyte character length (UTF-8) $matches[0][1] = mb_strpos($found_text, $matches[0][0]); ...P.S. The $pattern variable must use "/u" switch for Unicode!!!