Preg替换-如何保存在波斯字符命名的上传文件与php


preg replace - how to save an uploaded file named in persian characters with php?

我想用" "代替特殊字符,这意味着只支持字母和数字字符,这段代码到目前为止工作!

function clean($string) {
   return preg_replace('/[^A-Za-z0-9 ]/', ' ', $string);
}

但是现在当我尝试允许波斯语(波斯语)字符,问题发生了,这是$字符串变成空!当我尝试使用用户给出的其他例子时,例如:

function clean($string) {
return preg_replace('/([^A-Za-z0-9 ])-(^['x{0600}-'x{06FF}]*$)/', ' ', $string);
}

文件名保存为اذتاتا.

我该如何解决这个问题?

提前感谢!

我自己得到了答案,文件保存得很好,问题是我的服务器没有utf-8,所以它向我显示了这些字符,至于必须限制用户只使用英语和波斯语字母和数字,我想出了这个解决方案:

$('input').keypress(function( e ) {    
    if(!/([ابپتثجچحخدذرزژشسصضطظعغفقکگلمنوهیء a-zA-Z0-9])+/.test(String.fromCharCode(e.which)))
        return false;
});