homepage Welcome to WebmasterWorld Guest from 23.23.57.144
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Special Characters
Is there a PHP function that searches for only special chars?
d40sithui

5+ Year Member



 
Msg#: 3260436 posted 3:52 pm on Feb 22, 2007 (gmt 0)

~`!@#$%^&*()_-+=\][{}:;"'?/>.<,

does anyone know of a function in PHP (if any) that finds only special characters?

-khanh

 

cmarshall

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3260436 posted 3:58 pm on Feb 22, 2007 (gmt 0)

~`!@#$%^&*()_-+=\][{}:;"'?/>.<,

does anyone know of a function in PHP (if any) that finds only special characters?

preg_match [us3.php.net] ( "/~`!@#$%^&*()_-+=\\][{}:;"'?\/>.<,/", $string ); (Note the additional backslashes -actually, you'll need more than them. There's all kinds of special regex characters in there. Use preg_quote [us3.php.net] to scrub the regex.)

So it might look like
preg_match("/".preg_quote("~`!@#$%^&*()_-+=\\][{}:;\"'?/>.<,","/")."/", $string);

mcibor

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3260436 posted 4:13 pm on Feb 22, 2007 (gmt 0)

I would use negation query:

preg_match ( "@[^a-z0-9 ]+@i", $string );

It will also find line breaks

henry0

WebmasterWorld Senior Member henry0 us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3260436 posted 6:37 pm on Feb 22, 2007 (gmt 0)

As mcibor shows it is better to check for what's allowed than the reverse

you will have no problem at selecting what you agree to get and might very often forget a few items to disallow.

d40sithui

5+ Year Member



 
Msg#: 3260436 posted 7:18 pm on Feb 26, 2007 (gmt 0)

thanks for the help guys!

-khanh

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.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved