【发布时间】:2012-05-14 02:55:31
【问题描述】:
我有一个对文本进行 slugifying 的函数,它运行良好,只是我需要用“/”替换“:”。目前它用“-”替换所有非字母或数字。这里是:
function slugify($text)
{
// replace non letter or digits by -
$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
// trim
$text = trim($text, '-');
// transliterate
if (function_exists('iconv'))
{
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
}
// lowercase
$text = strtolower($text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);
if (empty($text))
{
return 'n-a';
}
return $text;
}
【问题讨论】: