Last active
April 24, 2019 13:08
-
-
Save utilmind/c78e98f23ff0cba6073d8df4b9bc3228 to your computer and use it in GitHub Desktop.
Правило милозвучності в строках
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
/* This code make for Ukrainian language only. | |
Перетвоює пару В-У в строках відповідно до правила милозвучності української мови. | |
Перетворює «в» на «у» чи навпаки, залежно від контексту (наявності голосних-приголосних поруч). | |
Фаворит Експертів в номінації --> Фаворит Експертів у номінації | |
Фаворит Успіху у номінації --> Фаворит Успіху в номінації | |
*/ | |
function mielophone($s, $l = false) { | |
global $lang; | |
if (!$l) $l = $lang; | |
if ($l != 'ua') return $s; | |
return preg_replace('/([аеиоуюяєіїАЕИОУЮЯЄІЇ])((<[^>]+?>)*?)((\s| | |\x{00A0}|<br\s*\/?>+)((<[^>]+?>)*?)у(\s| | |\x{00A0})([^вВ]))/u', '$1$2$5в$8$9', | |
preg_replace('/([^аеиоуюяєіїАЕИОУЮЯЄІЇ])((<[^>]+?>)*?)((\s| | |\x{00A0}|<br\s*\/?>+)((<[^>]+?>)*?)в(\s| | |\x{00A0})([^уУ]))/u', '$1$2$5у$8$9', | |
preg_replace('/(\s| | |\x{00A0}|<br\s*\/?>+)в(\s| | |\x{00A0})([вВ])/u', '$1у$2$3', | |
preg_replace('/(\s| | |\x{00A0}|<br\s*\/?>+)у(\s| | |\x{00A0})([уУ])/u', '$1в$2$3', $s)))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is unicode-friendly version. Legacy version, only for Windows-1251 encoding was following: