homepage Welcome to WebmasterWorld Guest from 184.72.184.104
register, login, search, subscribe, help, library, PubCon, announcements, recent posts, open posts,
Pubcon Website
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library : Charter : Moderators: coopster & eelixduppy & jatar k

PHP Server Side Scripting Forum

    
Strip out non-alpha numeric
rfontaine




msg:1281554
 12:24 pm on Jun 28, 2006 (gmt 0)

Hi,

I am looking for a php function that will efficiently strip from a phrase all characters that are not alpha or numeric:

keep only: a-z A-Z and 0-9

What might you recommend trying, other than the usual "RTFM"?

Thank you in advance

 

rfontaine




msg:1281555
 12:35 pm on Jun 28, 2006 (gmt 0)

oh, also spaces are allowed

adb64




msg:1281556
 1:11 pm on Jun 28, 2006 (gmt 0)

Do a preg_replace [nl2.php.net] of "/[^a-zA-Z0-9 ]/" with an empty string "".
Probably the pattern can be optimised, but this one should work for you.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
WebmasterWorld ® and PubCon ® are a Registered Trademarks of Pubcon Inc.
© Pubcon Inc. 1996-2012 all rights reserved