preg_replace的preg_replace_callback替代

时间:2015-07-16 09:00:43

标签: php regex preg-replace preg-replace-callback

我目前正在使用

preg_replace('/[^a-zA-Z0-9]+/', '_', $str)

使用preg_replace_callback的替代函数是什么?

1 个答案:

答案 0 :(得分:1)

我自己做了



function url_title($mystr){
	$result = '';
	$result .= preg_replace_callback(
                '/[^a-zA-Z0-9]+/',
                function ($matches) { return '_'; }, 
                $mystr);
						
	return strtolower($result);
}

$mystr = "some string here";
echo url_title($mystr);




相关问题