There was a similar PHP question preg_replace and windows-1251 (characters H and E)

But mine is somewhat different The windows-1251 encoding doesn’t contain the uppercase characters и and,, if there are small letters in the search query - и and несмотря, despite ignoring case, for example

<? $findme1 = 'ч'; $findme2 = 'ё'; $findme3 = 'Ч'; $findme4 = 'Ё'; $findme5 = 'у'; $findme6 = 'У'; $mystring1 = 'СУТОЧНОЁ'; $pos1 = mb_stripos($mystring1, $findme1); $pos2 = mb_stripos($mystring1, $findme2); $pos3 = mb_stripos($mystring1, $findme3); $pos4 = mb_stripos($mystring1, $findme4); $pos5 = mb_stripos($mystring1, $findme5); $pos6 = mb_stripos($mystring1, $findme6); echo "ч - $pos1, ё - $pos2, Ч - $pos3, Ё - $pos4, у - $pos5, У - $pos6"; ?> соответственно выводит ч - , ё - , Ч - 4, Ё - 7, у - 1, У - 1 

PHP Version 5.2.12

PCRE Library Version 7.9 2009-04-11

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

2 answers 2

Test (PHP Version 5.6.8):

 <html> <head> <meta charset="Windows-1251"> <title>чё-ЧЁ?</title> </head> <body> <?php $findme1 = 'ч'; $findme2 = 'Ч'; $findme3 = 'ё'; $findme4 = 'Ё'; $findme5 = 'у'; $findme6 = 'У'; $mystring1 = 'СУТОЧНОЁ'; $pos1 = mb_stripos($mystring1, $findme1); $pos2 = mb_stripos($mystring1, $findme2); $pos3 = mb_stripos($mystring1, $findme3); $pos4 = mb_stripos($mystring1, $findme4); $pos5 = mb_stripos($mystring1, $findme5); $pos6 = mb_stripos($mystring1, $findme6); echo "ч - $pos1, Ч - $pos2, ё - $pos3, Ё - $pos4, у - $pos5, У - $pos6"; foreach (array('СУТОЧНОЁ', 'суточноё') as $mystring){ print("<br><br>mystring = '$mystring'"); $mystring_UTF16 = mb_convert_encoding($mystring, "UTF-16"); $mystring_CP1251 = mb_convert_encoding($mystring, "CP1251"); $find = array("Ч", "ч", "Ё", "ё", "У", "у"); foreach($find as $f){ $f_UTF16 = mb_convert_encoding($f, "UTF-16"); $f_CP1251 = mb_convert_encoding($f, "CP1251"); printf("<br>%s (UTF-16) - %02d(mb_stripos) : %02d(stripos) &emsp; %s (CP1251) - %02d(mb_stripos) : %02d(stripos)", $f, mb_stripos($mystring_UTF16, $f_UTF16), stripos($mystring_UTF16, $f_UTF16), $f, mb_stripos($mystring_CP1251, $f_CP1251), stripos($mystring_CP1251, $f_CP1251) ); } } ?> </body> </html> 

Results:

 h - 4, H - 4, e - 7, E - 7, y - 1, Y - 1

 mystring = 'DAILY'
 H (UTF-16) - 08 (mb_stripos): 08 (stripos) H (CP1251) - 00 (mb_stripos): 04 (stripos)
 h (UTF-16) - 00 (mb_stripos): 00 (stripos) h (CP1251) - 00 (mb_stripos): 00 (stripos)
 E (UTF-16) - 14 (mb_stripos): 14 (stripos) E (CP1251) - 00 (mb_stripos): 07 (stripos)
 g (UTF-16) - 00 (mb_stripos): 00 (stripos) g (CP1251) - 00 (mb_stripos): 00 (stripos)
 Do (UTF-16) - 02 (mb_stripos): 02 (stripos) Do (CP1251) - 00 (mb_stripos): 01 (stripos)
 (UTF-16) - 00 (mb_stripos): 00 (stripos); (CP1251) - 00 (mb_stripos): 00 (stripos)

 mystring = 'diurnal'
 H (UTF-16) - 00 (mb_stripos): 00 (stripos) H (CP1251) - 00 (mb_stripos): 00 (stripos)
 h (UTF-16) - 08 (mb_stripos): 08 (stripos) h (CP1251) - 00 (mb_stripos): 04 (stripos)
 E (UTF-16) - 00 (mb_stripos): 00 (stripos) E (CP1251) - 00 (mb_stripos): 00 (stripos)
 g (UTF-16) - 14 (mb_stripos): 14 (stripos) g (CP1251) - 00 (mb_stripos): 07 (stripos)
 Y (UTF-16) - 00 (mb_stripos): 00 (stripos) Y (CP1251) - 00 (mb_stripos): 00 (stripos)
 (UTF-16) - 02 (mb_stripos): 02 (stripos) (CP1251) - 00 (mb_stripos): 01 (stripos)

That is, in the newer version of the letter "h / h", "ё / Ё", "at / at" are treated the same, but nevertheless:

  1. mb_stripos does not work with single-byte Cyrillic encodings.
  2. mb_stripos and stripos case-sensitive Cyrillic.

    A well-known fact is that starting from 5.6 is easier

    eventually got around the side

     //предварительно прописываем локали $locales = array("Russian_Russia.1251", "ru_RU.CP1251", "ru_RU.cp1251", "ru_RU", "RU", "rus_RUS.1251"); if (false === setlocale(LC_ALL, $locales)) { // failed to set locale } $findme1 = 'ч'; $findme2 = 'ё'; $findme3 = 'Ч'; $findme4 = 'Ё'; $findme5 = 'у'; $findme6 = 'У'; $mystring1 = 'СУТОЧНОЁ'; $pos1 = mb_stripos(strtolower($mystring1), strtolower($findme1)); $pos2 = mb_stripos(strtolower($mystring1), strtolower($findme2)); $pos3 = mb_stripos(strtolower($mystring1), strtolower($findme3)); $pos4 = mb_stripos(strtolower($mystring1), strtolower($findme4)); $pos5 = mb_stripos(strtolower($mystring1), strtolower($findme5)); $pos6 = mb_stripos(strtolower($mystring1), strtolower($findme6)); echo "ч - $pos1, ё - $pos2, Ч - $pos3, Ё - $pos4, у - $pos5, У - $pos6"; 

    displays accordingly

    h - 4, g - 7, H - 4, Y - 7, y - 1, Y - 1