Welcome to WebmasterWorld Guest from 54.162.164.247

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Special Characters

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

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

Preferred Member

10+ Year Member

joined:Jan 16, 2007
posts:477
votes: 0


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

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

-khanh

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 21, 2005
posts:1526
votes: 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);
4:13 pm on Feb 22, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 26, 2003
posts:1133
votes: 0


I would use negation query:

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

It will also find line breaks

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

Senior Member from FR 

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

joined:Apr 19, 2003
posts:4409
votes: 5


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.

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

Preferred Member

10+ Year Member

joined:Jan 16, 2007
posts:477
votes: 0


thanks for the help guys!

-khanh

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members