I have a text area where people enter large texts (5000-10000) characters. What I want is to remove some characters before storing it to a file.
So only the following WILL NOT BE REMOVED
1) SINGLE SPACE
2) ENGLISH ALPHABETS
3) EUROPEAN CHARACTERS
any other character, no matter what they are should be removed.
Have a look at the filter_input command, where you can apply various [url=
"http://www.php.net/manual/en/filter.filters.sanitize.php"]types of filters.
$message = filter_input(INPUT_POST, 'message', FILTER_SANITIZE_STRING);
Well thanks, but I wrote a solution like :
$txt = preg_replace('/[^A-Za-zÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïñòóôõöøùúûüýÿAaAaAaCcCcCcCcDdÐdEeEeEeEeEeGgGgGgGgHhHhIiIiIiIiIi??JjKkLlLlLl??LlNnNnNn?OoOoOoŒœRrRrRrSsSsSsŠšTtTtTtUuUuUuUuUuUuWwYyŸZzZzŽž?ƒOoUuAaIiOoUuUuUuUuUu?????? ]/i', ' ', $txt1);
Now, here are the issues
1) If I enter spacial characters like „”–…«» they are not removed.
2) If the text has a URL, the script removes the symbols from that too.
Can any one please suggest what is the best way to only allow ENGLISH CHARACTERS, EUROPEAN CHARACTERS, SINGLE SPACE in text, and if there is a URL then do not remove : or & or / or . from that ?
Edit: ack misread the line
Well, it's an ugly fix but... You could use a function to take the string, break it into words (eliminating any empty ones will get rid of excess spaces between words)...then foreach word, check for a URL (and set a flag) break each word to characters, ASCII-check them (adding numbers to the valid-ascii range if the flag is set), and smash it all back together when you're done.
Dont see why preg_replace wouldnt hit those characters, though.
Yes, StarLion you wrote exactly what I was thinking that using explode() I break the words by single spaces and then check each word one by one.