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

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, ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-15-2005
Sugapablo
 
Posts: n/a
Default 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@12jabber.com <--jabber IM ]

Reply With Quote
  #2 (permalink)  
Old 01-15-2005
porneL
 
Posts: n/a
Default Re: Function to strip all but letters, numbers, and _?

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);}
Reply With Quote
  #3 (permalink)  
Old 01-16-2005
Alvaro G. Vicario
 
Posts: n/a
Default Re: Function to strip all but letters, numbers, and _?

*** 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
--
Reply With Quote
  #4 (permalink)  
Old 01-16-2005
Chung Leong
 
Posts: n/a
Default Re: Function to strip all but letters, numbers, and _?

"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);


Reply With Quote
  #5 (permalink)  
Old 01-22-2005
Alvaro G. Vicario
 
Posts: n/a
Default Re: Function to strip all but letters, numbers, and _?

*** 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
--
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:28 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0