如何忽略通過此操作實現的單引號?如何忽略正則表達式中的單個字符
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'包含撇號? –