Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function utf8convert($str) {
- if(!$str) return false;
- $utf8 = array(
- 'a'=>'á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ|Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ',
- 'd'=>'đ|Đ',
- 'e'=>'é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ|É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ',
- 'i'=>'í|ì|ỉ|ĩ|ị|Í|Ì|Ỉ|Ĩ|Ị',
- 'o'=>'ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ|Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ỗ|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ',
- 'u'=>'ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự|Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự',
- 'y'=>'ý|ỳ|ỷ|ỹ|ỵ|Ý|Ỳ|Ỷ|Ỹ|Ỵ',
- );
- foreach($utf8 as $ascii=>$uni) $str = preg_replace("/($uni)/i",$ascii,$str);
- return $str;
- }
- function utf8tourl($text){
- $text = strtolower(utf8convert($text));
- $text = str_replace( "ß", "ss", $text);
- $text = str_replace( "%", "", $text);
- $text = preg_replace("/[^_a-zA-Z0-9 -]
- /", "",$text);
- $text = str_replace(array('%20', ' '), '-', $text);
- $text = str_replace("----","-",$text);
- $text = str_replace("---","-",$text);
- $text = str_replace("--","-",$text);
- return $text;
- }
- $utf8_str = "Thu, 09 Jul 2015 23:44:02 GMT +7
- Và mong Anh lượng thứ cho qua, Em xin chân thành cảm ơn.";
- $new_str = utf8tourl(utf8convert($utf8_str));
- //$new_str = utf8tourl(utf8convert($utf8_str)); //cho seo
- echo $new_str;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement