如何忽略通过此操作实现的单引号?如何忽略正则表达式中的单个字符
function FixNameForLink($str){
// Swap out Non "Letters" with a -
$text = preg_replace('/[^\\pL\d]+/u', '-', $str);
// Trim out extra -'s
$text = trim($text, '-');
// Convert letters that we have left to the closest ASCII representation
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
// Make text lowercase
$text = strtolower($text);
// Strip out anything we haven't been able to convert
$text = preg_replace('/[^-_\w]+/', '', $text);
return $text;
}
我给一个名字Steven's Barbecue
,我想将其转换为一个适当的链接,如steven-s-barbecue
,但不知何故,我需要能够转换“成另一种性格像_
对于澄清(以避免混淆...),链接需要是steven_s-barbecue
为什么不只是使用urlencode()? – 2013-12-18 18:55:48
,因为我不需要在网址中使用空格之类的+或%20 ...我需要 - 。 – Kevin
那么'\\ pL'包含撇号? –