Lọc dấu tiếng Việt


Có thể thay nhiều khoảng trắng thành –
<?php
/*
Plugin Name: Vietnamese Permalinks
Plugin URI: http://web20vn.com
Description: Khong dau
Author: Web20vn.com
Version: 1.0
Author URI: http://web20vn.com
*/

function khongdau1($str) {
$search = array (
‘#(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)#’,
‘#(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)#’,
‘#(ì|í|ị|ỉ|ĩ)#’,
‘#(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)#’,
‘#(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)#’,
‘#(ỳ|ý|ỵ|ỷ|ỹ)#’,
‘#(đ)#’,
‘#(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)#’,
‘#(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)#’,
‘#(Ì|Í|Ị|Ỉ|Ĩ)#’,
‘#(Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)#’,
‘#(Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)#’,
‘#(Ỳ|Ý|Ỵ|Ỷ|Ỹ)#’,
‘#(Đ)#’,
“/[^a-zA-Z0-9\-\_]/”,
;
$replace = array (
‘a’,
‘e’,
‘i’,
‘o’,
‘u’,
‘y’,
‘d’,
‘A’,
‘E’,
‘I’,
‘O’,
‘U’,
‘Y’,
‘D’,
‘-‘,
;
$str = preg_replace($search, $replace, $str);
$str = preg_replace(‘/(-)+/’, ‘-‘, $str);
return $str;
}

remove_action(‘sanitize_title’, ‘sanitize_title_with_dashes’);
add_action(‘sanitize_title’, ‘khongdau1’);
?>

Theo phpbasic

Advertisements
By dbglory Posted in PHP

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s