#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    3
    Rep Power
    0
    I've used the following code to take a string, remove offensive char, and make sure there is only one space between each word. The space manipulation is fairly easy, but I'm new at regular expressions. Is there a way to accomplish the other removal part? Ideally, I want just letters and numbers, spaces, and nothing else...

    //Remove no-good char like metas and so on
    $bad_array = ("!","@","#","$","%","&","_","<",">",":",";","|",",",".","+","*","?","[","^","]","(","$",")");
    while (list($key,$val) = each ($bad_array)) {
    if(!empty($val)) {
    $text = str_replace($val, " ",$key_words);
    }
    }
    //Remove xs spaces, only one between each char
    $key_words = preg_replace("/s+/", " ", $key_words);

    [This message has been edited by Richard Diggler (edited August 25, 2000).]
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 1999
    Location
    Annapolis, Maryland US
    Posts
    113
    Rep Power
    16
    <?
    // replace excess spaces with single space
    $var=ereg_replace("[ ]{2,}", " ", $var);

    // remove non-alphanumeric, non-space
    $var=ereg_replace("[^a-zA-Z0-9 ]", "", $var);
    ?>

Similar Threads

  1. Very simple Reg Exp question.....
    By crispy_veg in forum PHP Development
    Replies: 1
    Last Post: February 14th, 2004, 08:22 AM
  2. Regular expression question
    By bonzaitrimmer in forum .Net Development
    Replies: 1
    Last Post: January 26th, 2004, 08:41 PM
  3. PHP question re. reg. exps.
    By jfitie in forum PHP Development
    Replies: 1
    Last Post: December 9th, 2003, 03:29 PM
  4. DBI warnings -- plz help
    By pranesh in forum Perl Programming
    Replies: 4
    Last Post: December 1st, 2003, 07:52 PM
  5. Radio Buttons
    By Ulysses Freeman in forum HTML Programming
    Replies: 4
    Last Post: November 15th, 2003, 10:57 PM

IMN logo majestic logo threadwatch logo seochat tools logo