This is a discussion on Function to strip all but letters, numbers, and _? within the PHP Language forums, part of the PHP Programming Forums category; Does anyone have a handy-dandy function they can quickly post that strips everything from a string except for letters, ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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@12jabber.com <--jabber IM ] |
|
|||
|
On Sat, 15 Jan 2005 14:59:18 -0500, Sugapablo <russ@REMOVEsugapablo.com>
wrote: > Does anyone have a handy-dandy function they can quickly post that strips > everything from a string except for letters, numbers, & underscores? $stripped = preg_replace('/[^a-z0-9_]/i','',$string); -- * html {redirect-to: url(http://pornel.ldreams.net);} |
|
|||
|
*** Sugapablo escribió/wrote (Sat, 15 Jan 2005 14:59:18 -0500):
> Does anyone have a handy-dandy function they can quickly post that strips > everything from a string except for letters, numbers, & underscores? function strip_all_but_letters_numbers_and_underscores($tex t){ 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 -- |
|
|||
|
"Alvaro G. Vicario" <kAlvaroNOSPAMTHANKS@terra.es> wrote in message
news:1uzyis8ekuxw9.v2x1zufftpv4.dlg@40tude.net... > *** Sugapablo escribió/wrote (Sat, 15 Jan 2005 14:59:18 -0500): > > Does anyone have a handy-dandy function they can quickly post that strips > > everything from a string except for letters, numbers, & underscores? > > function strip_all_but_letters_numbers_and_underscores($tex t){ > 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 > -- 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); |
|
|||
|
*** Chung Leong escribió/wrote (Sat, 15 Jan 2005 23:07:33 -0500):
> 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); 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 -- |