Thay khoảng trống bằng gạch ngang vào URL


function url_title($str, $separator = ‘-‘, $lowercase = FALSE) {
if ($separator == ‘dash’) {
$separator = ‘-‘;
} else if ($separator == ‘underscore’) {
$separator = ‘_’;
}

$q_separator = preg_quote($separator);

$trans = array(
‘&.+?;’ => ”,
‘[^a-z0-9 _-]’ => ”,
‘\s+’ => $separator,
‘(‘ . $q_separator . ‘)+’ => $separator
);

$str = strip_tags($str);

foreach ($trans as $key => $val) {
$str = preg_replace(“#” . $key . “#i”, $val, $str);
}

if ($lowercase === TRUE) {
$str = strtolower($str);
}

return trim($str, $separator);
}

Advertisements

Để lại comment đê!

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s