[PHP] Chuyển chuỗi tiếng việt có dấu thành không dấu
![[PHP] Chuyển chuỗi tiếng việt có dấu thành không dấu TiengViet [PHP] Chuyển chuỗi tiếng việt có dấu thành không dấu](http://gi118.photobucket.com/groups/o89/PFAG6T8722/TiengViet.jpg)
Hàm chuyển chuỗi tiếng việt có dấu thành tiếng việt không dấu:
-Yêu cầu: Bạn phải lưu file php theo charset là UTF-8. Có thể dùng Notepad hoặc Editplus version mới nhất
Code:
function khongdau($str) {
$str = preg_replace(“/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|� �|ặ|ẳ|ẵ)/”, ‘a’, $str);
$str = preg_replace(“/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/”, ‘e’, $str);
$str = preg_replace(“/(ì|í|ị|ỉ|ĩ)/”, ‘i’, $str);
$str = preg_replace(“/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|� �|ợ|ở|ỡ)/”, ‘o’, $str);
$str = preg_replace(“/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/”, ‘u’, $str);
$str = preg_replace(“/(ỳ|ý|ỵ|ỷ|ỹ)/”, ‘y’, $str);
$str = preg_replace(“/(đ)/”, ‘d’, $str);$str = preg_replace(“/(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|� �|Ặ|Ẳ|Ẵ)/”, ‘A’, $str);
$str = preg_replace(“/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/”, ‘E’, $str);
$str = preg_replace(“/(Ì|Í|Ị|Ỉ|Ĩ)/”, ‘I’, $str);
$str = preg_replace(“/(Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|� �|Ợ|Ở|Ỡ)/”, ‘O’, $str);
$str = preg_replace(“/(Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/”, ‘U’, $str);
$str = preg_replace(“/(Ỳ|Ý|Ỵ|Ỷ|Ỹ)/”, ‘Y’, $str);
$str = preg_replace(“/(Đ)/”, ‘D’, $str);
//$str = str_replace(” “, “-”, str_replace(“&*#39;”,”",$str));
return $str;
}
-Cách sử dụng:
Code:
<?php
$string = “Cộng hòa xã hội chủ nghĩa Việt Nam”;
$xstring = khongdau($string);echo $xstring;
//Kết quả:
//Output: Cong hoa xa hoi chu nghia Viet Nam
?>
Nguồn: Internet

--/
Tags: 









sugiatinhyeu_thantinhyeu3
manlivo
manlivo@gmail.com