homepage Welcome to WebmasterWorld Guest from 54.226.213.228
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




msg:3260438
 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




msg:3260443
 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




msg:3260454
 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




msg:3260613
 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




msg:3264578
 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