Welcome to WebmasterWorld Guest from 54.226.246.160

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Special Characters

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

     

d40sithui

3:52 pm on Feb 22, 2007 (gmt 0)

5+ Year Member



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

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

-khanh

cmarshall

3:58 pm on Feb 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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

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

4:13 pm on Feb 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would use negation query:

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

It will also find line breaks

henry0

6:37 pm on Feb 22, 2007 (gmt 0)

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



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

7:18 pm on Feb 26, 2007 (gmt 0)

5+ Year Member



thanks for the help guys!

-khanh

 

Featured Threads

Hot Threads This Week

Hot Threads This Month