문제

I want to replace the special characters by " " it means only alphabetical and numeric characters are supported, this code worked so far!

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

but now when I try to allow persian (farsi) characters as well, the problem happens which is the $string becomes empty! and when I tried to use other examples given by users for example:

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

the file name saves as اذتاتا.

any ideas on how can I solve this?

thank you in advance!

도움이 되었습니까?

해결책

got the answer on my own, the files were getting saved just right, the problem was that my server didn't have utf-8 so it was showing me these characters, and as for having to limit the user to only use english and persian alphabet and number I came up with this solution:

$('input').keypress(function( e ) {    
    if(!/([ابپتثجچحخدذرزژشسصضطظعغفقکگلمنوهیء a-zA-Z0-9])+/.test(String.fromCharCode(e.which)))
        return false;
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top