Advertisement
tranquangchau

utf8 to kog dau

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