0

why following code piece does not match with option i?

#!/usr/bin/env php7.4

<?php

        $str = 'БОЛЬШАЯ КОШКА ЛОВИТ МЫШЬ';

        echo '--- $str ----' . "\n";
        echo $str . "\n";

        $pattern = "/КОШКА/i";
        if(preg_match($pattern,$str,$out)) {
                echo "--- Both UPPER case ---\n";
                print_r($out);
        }

        $pattern = "/кошка/i";
        if(preg_match($pattern,$str,$out)) {
                echo "--- /кошка/i ---\n";
                print_r($out);
        } else {
                echo "--- no match with /кошка/i --\n";
        }
?>

Output

(uiserver):u99246072:~/work/php/x$ ./x.php
X-Powered-By: PHP/7.4.11
Content-type: text/html; charset=UTF-8


--- $str ----
БОЛЬШАЯ КОШКА ЛОВИТ МЫШЬ
--- Both UPPER case ---
Array
(
    [0] => КОШКА
)
--- no match with /кошка/i --
(uiserver):u99246072:~/work/php/x$
kaya3
  • 47,440
  • 4
  • 68
  • 97
Polar Bear
  • 6,762
  • 1
  • 5
  • 12
  • Pretty sure this is due to the cyrillic charset and PCRE's inability to see the relationship between capitol and lowercase letters in that charset – Wesley Smith Nov 02 '20 at 04:56
  • Works fine with the correct flag. – mario Nov 02 '20 at 04:57
  • Thank you, option `/u` solved _utf8_ problem. Note: is there a web page where option flags described preferably with code samples? Read documentation [preg_match](https://www.php.net/manual/en/function.preg-match.php) but not found `/u` flag in description. After tip here went with _search_ and found this option mentioned in comments to documentation. – Polar Bear Nov 02 '20 at 05:16

0 Answers0