Frage

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!

War es hilfreich?

Lösung

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;
});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top