Created
December 19, 2015 07:52
-
-
Save thanhhh/20d721ccae474038cccf to your computer and use it in GitHub Desktop.
Clear Vietnamese signs by PHP
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 | |
class StringUtils | |
{ | |
static $unicode = array( | |
'a'=>'á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ', | |
'd'=>'đ', | |
'e'=>'é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ', | |
'i'=>'í|ì|ỉ|ĩ|ị', | |
'o'=>'ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ', | |
'u'=>'ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự', | |
'y'=>'ý|ỳ|ỷ|ỹ|ỵ', | |
'A'=>'Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ', | |
'D'=>'Đ', | |
'E'=>'É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ', | |
'I'=>"Í|Ì|Ỉ|Ĩ|Ị", | |
'O'=>"Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ỗ|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ", | |
'U'=>'Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự', | |
'Y'=>'Ý|Ỳ|Ỷ|Ỹ|Ỵ', | |
); | |
/** | |
* Clear Vietnamese's signs from string | |
* @param $str string | |
* @return string The result string without Vietnamese's signs | |
*/ | |
public static function clearStrVnSigns ($str){ | |
//mb_internal_encoding('UTF-8'); | |
foreach(static::$unicode as $nonUnicode=>$uni){ | |
$str = preg_replace("/($uni)/u", $nonUnicode, $str); | |
} | |
return $str; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment