-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
В модуль Text добавлен метод транслитерации
- Loading branch information
Showing
1 changed file
with
95 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -320,7 +320,8 @@ public function CodeSourceParser($sText) | |
* @param string $sText Исходный текст | ||
* @return array | ||
*/ | ||
public function Cut($sText) { | ||
public function Cut($sText) | ||
{ | ||
$sTextShort = $sText; | ||
$sTextNew = $sText; | ||
$sTextCut = null; | ||
|
@@ -335,4 +336,97 @@ public function Cut($sText) { | |
|
||
return array($sTextShort, $sTextNew, $sTextCut ? htmlspecialchars($sTextCut) : null); | ||
} | ||
|
||
/** | ||
* Выполняет транслитерацию текста | ||
* | ||
* @param $sText | ||
* @param bool $bLower | ||
* @return mixed|string | ||
*/ | ||
public function Transliteration($sText, $bLower = true) | ||
{ | ||
$aConverter = array( | ||
'а' => 'a', | ||
'б' => 'b', | ||
'в' => 'v', | ||
'г' => 'g', | ||
'д' => 'd', | ||
'е' => 'e', | ||
'ё' => 'e', | ||
'ж' => 'zh', | ||
'з' => 'z', | ||
'и' => 'i', | ||
'й' => 'y', | ||
'к' => 'k', | ||
'л' => 'l', | ||
'м' => 'm', | ||
'н' => 'n', | ||
'о' => 'o', | ||
'п' => 'p', | ||
'р' => 'r', | ||
'с' => 's', | ||
'т' => 't', | ||
'у' => 'u', | ||
'ф' => 'f', | ||
'х' => 'h', | ||
'ц' => 'c', | ||
'ч' => 'ch', | ||
'ш' => 'sh', | ||
'щ' => 'sch', | ||
'ь' => "'", | ||
'ы' => 'y', | ||
'ъ' => "'", | ||
'э' => 'e', | ||
'ю' => 'yu', | ||
'я' => 'ya', | ||
'А' => 'A', | ||
'Б' => 'B', | ||
'В' => 'V', | ||
'Г' => 'G', | ||
'Д' => 'D', | ||
'Е' => 'E', | ||
'Ё' => 'E', | ||
'Ж' => 'Zh', | ||
'З' => 'Z', | ||
'И' => 'I', | ||
'Й' => 'Y', | ||
'К' => 'K', | ||
'Л' => 'L', | ||
'М' => 'M', | ||
'Н' => 'N', | ||
'О' => 'O', | ||
'П' => 'P', | ||
'Р' => 'R', | ||
'С' => 'S', | ||
'Т' => 'T', | ||
'У' => 'U', | ||
'Ф' => 'F', | ||
'Х' => 'H', | ||
'Ц' => 'C', | ||
'Ч' => 'Ch', | ||
'Ш' => 'Sh', | ||
'Щ' => 'Sch', | ||
'Ь' => "'", | ||
'Ы' => 'Y', | ||
'Ъ' => "'", | ||
'Э' => 'E', | ||
'Ю' => 'Yu', | ||
'Я' => 'Ya', | ||
" " => "-", | ||
"." => "", | ||
"/" => "-", | ||
"_" => "-" | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
); | ||
$sRes = strtr($sText, $aConverter); | ||
if ($sResIconv = @iconv("UTF-8", "ISO-8859-1//IGNORE//TRANSLIT", $sRes)) { | ||
$sRes = $sResIconv; | ||
} | ||
$sRes = preg_replace('/[^A-Za-z0-9\-]/', '', $sRes); | ||
$sRes = preg_replace('/\-+/', '-', $sRes); | ||
This comment has been minimized.
Sorry, something went wrong.
psnet
|
||
if ($bLower) { | ||
$sRes = strtolower($sRes); | ||
} | ||
return $sRes; | ||
} | ||
} |
Туда же украинский алфавит:
не знаю почему паника у iconv на кавычки, но суть такова