Created
May 26, 2015 10:45
-
-
Save ivansky/c740ef02b59596d7862c to your computer and use it in GitHub Desktop.
Search Keyword Prepare
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Remove from string all invalid characters | |
* Leave only English, Russian, Turkish, Kazakh and Numbers | |
* @link http://www.unicode.org/charts/ | |
* @param string $w | |
* @return string | |
*/ | |
function prepareSearchKeyword($w){ | |
// АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМм | |
// НнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъ | |
// ЫыЬьЭэЮюЯя | |
$RUSSIAN = '\\x{0410}-\\x{045F}'; | |
// çğışöü ÇĞİŞÖÜ | |
$TURKISH = '\\x{00E7}\\x{011F}\\x{0131}\\x{015F}'. | |
'\\x{00F6}\\x{00FC}\\x{00C7}\\x{011E}'. | |
'\\x{0130}\\x{015E}\\x{00D6}\\x{00DC}'; | |
//ӘҒҚҢӨҮҰҺІ әғқңөүұһі | |
$KAZAKH = '\\x{04A2}\\x{04A3}\\x{0406}\\x{0456}'. | |
'\\x{0492}\\x{0493}\\x{049A}\\x{049B}'. | |
'\\x{04AE}\\x{04AF}\\x{04B0}\\x{04B1}'. | |
'\\x{04BA}\\x{04BB}\\x{04D8}\\x{04D9}'. | |
'\\x{04E8}\\x{04E9}'; | |
$w = preg_replace('/[^a-z0-9'.$RUSSIAN.$TURKISH.$KAZAKH.']+/ui', ' ', $w); | |
$w = preg_replace('/[\s]+/', ' ', $w); | |
return mb_strtolower(trim($w),'UTF-8'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment