1

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!

Amin Jafari
  • 7,157
  • 2
  • 18
  • 43
  • First of all you should check what character encoding the underlying file system uses … – CBroe Mar 17 '14 at 13:37
  • Using `Persian` characters in file names is not a good idea, specially in Internet. Many systems does not have full support of them. – Afshar Mohebi Mar 18 '14 at 06:09

1 Answers1

2

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;
});
Amin Jafari
  • 7,157
  • 2
  • 18
  • 43