SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with Removing Un wanted Characters

    Hello

    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.

    Please help

    Thanks
    Zeeshan

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,718
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    Have a look at the filter_input command, where you can apply various types of filters.

    Code php:
    $message = filter_input(INPUT_POST, 'message', FILTER_SANITIZE_STRING);
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well thanks, but I wrote a solution like :

    PHP Code:
        $txt preg_replace('/[^A-Za-zAaAaAaCcCcCcCcDddEeEeEeEeEeGgGgGgGgHhHhIiIiIiIiIi??JjKkLlLlLl??LlNnNnNn?OoOoOoRrRrRrSsSsSsTtTtTtUuUuUuUuUuUuWwYyZzZz?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 ?

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •