Allow dot in php preg_replace
I'm using The perfect PHP clean url generator to clean 开发者_如何学运维some file names with an upload script (as well as to clean my permalinks elsewhere). How might I modify it to allow a .
if the function looks like this:
setlocale(LC_ALL, 'en_US.UTF8');
function toAscii($str, $replace=array(), $delimiter='-', $exception = '') {
if( !empty($replace) ) {
$str = str_replace((array)$replace, ' ', $str);
}
$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
$clean = strtolower(trim($clean, '-'));
$clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
return $clean;
}
Thanks in advance.
EDIT Modified the function slightly to reflect my actual usage - sorry about that.
So you just want to avoid replacing literal .
characters, is that correct? The dot should be interpreted literally if it's inside a character class, so your first regex line would just become:
$clean = preg_replace("/[^a-zA-Z0-9\/_|+ .-]/", '', $clean);
精彩评论