Function to strip all but letters, numbers, and _?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sugapablo

    Function to strip all but letters, numbers, and _?

    Does anyone have a handy-dandy function they can quickly post that strips
    everything from a string except for letters, numbers, & underscores?

    --
    [ Sugapablo ]
    [ http://www.sugapablo.com <--music ]
    [ http://www.sugapablo.net <--personal ]
    [ sugapablo@12jab ber.com <--jabber IM ]

  • porneL

    #2
    Re: Function to strip all but letters, numbers, and _?

    On Sat, 15 Jan 2005 14:59:18 -0500, Sugapablo <russ@REMOVEsug apablo.com>
    wrote:
    [color=blue]
    > Does anyone have a handy-dandy function they can quickly post that strips
    > everything from a string except for letters, numbers, & underscores?[/color]

    $stripped = preg_replace('/[^a-z0-9_]/i','',$string);


    --
    * html {redirect-to: url(http://pornel.ldreams. net);}

    Comment

    • Alvaro G. Vicario

      #3
      Re: Function to strip all but letters, numbers, and _?

      *** Sugapablo escribió/wrote (Sat, 15 Jan 2005 14:59:18 -0500):[color=blue]
      > Does anyone have a handy-dandy function they can quickly post that strips
      > everything from a string except for letters, numbers, & underscores?[/color]

      function strip_all_but_l etters_numbers_ and_underscores ($text){
      return preg_replace('/[^\w\d_]+/', '', $text);
      }

      --
      -+ Álvaro G. Vicario - Burgos, Spain
      +- http://www.demogracia.com (la web de humor barnizada para la intemperie)
      ++ Las dudas informáticas recibidas por correo irán directas a la papelera
      -+ I'm not a free help desk, please don't e-mail me your questions
      --

      Comment

      • Chung Leong

        #4
        Re: Function to strip all but letters, numbers, and _?

        "Alvaro G. Vicario" <kAlvaroNOSPAMT HANKS@terra.es> wrote in message
        news:1uzyis8eku xw9.v2x1zufftpv 4.dlg@40tude.ne t...[color=blue]
        > *** Sugapablo escribió/wrote (Sat, 15 Jan 2005 14:59:18 -0500):[color=green]
        > > Does anyone have a handy-dandy function they can quickly post that[/color][/color]
        strips[color=blue][color=green]
        > > everything from a string except for letters, numbers, & underscores?[/color]
        >
        > function strip_all_but_l etters_numbers_ and_underscores ($text){
        > return preg_replace('/[^\w\d_]+/', '', $text);
        > }
        >
        > --
        > -+ Álvaro G. Vicario - Burgos, Spain
        > +- http://www.demogracia.com (la web de humor barnizada para la[/color]
        intemperie)[color=blue]
        > ++ Las dudas informáticas recibidas por correo irán directas a la papelera
        > -+ I'm not a free help desk, please don't e-mail me your questions
        > --[/color]

        Eh, \w includes digits and the underscore. Also, capital letters are used to
        denote "not a meta character." Hence the following:

        preg_replace('/\W+/', '', $text);


        Comment

        • Alvaro G. Vicario

          #5
          Re: Function to strip all but letters, numbers, and _?

          *** Chung Leong escribió/wrote (Sat, 15 Jan 2005 23:07:33 -0500):[color=blue]
          > Eh, \w includes digits and the underscore. Also, capital letters are used to
          > denote "not a meta character." Hence the following:
          >
          > preg_replace('/\W+/', '', $text);[/color]

          Absolutely right. My code is what happens when you trust your memory :)

          --
          -+ Álvaro G. Vicario - Burgos, Spain
          +- http://www.demogracia.com (la web de humor barnizada para la intemperie)
          ++ Las dudas informáticas recibidas por correo irán directas a la papelera
          -+ I'm not a free help desk, please don't e-mail me your questions
          --

          Comment

          Working...