jaymc Posted November 24, 2006 Share Posted November 24, 2006 I want to check a variable to see if it contains any of the following chars[code]&?/\='",%+`[/code]I think its best to use preg_match but I'm just a little unsure how to set it all outI know the syntax ... preg_match("banned chars", $var);I just dont know how to format the banned chars in the functionAny help? Link to comment https://forums.phpfreaks.com/topic/28285-preg_match/ Share on other sites More sharing options...
Philip Posted November 24, 2006 Share Posted November 24, 2006 If you are wanting to format them into something else, why not use preg_replace?Ahh, I see what you're asking. See post below for a better answer - sorry. Link to comment https://forums.phpfreaks.com/topic/28285-preg_match/#findComment-129342 Share on other sites More sharing options...
fert Posted November 24, 2006 Share Posted November 24, 2006 you could use strstr[code]$words=array("%","&"...);$num=count($words);for($count=0;$count<$num;$count++){if(strstr($text,$words[$count])){die("the string has a disallowed charecter");}}[/code] Link to comment https://forums.phpfreaks.com/topic/28285-preg_match/#findComment-129343 Share on other sites More sharing options...
Nicklas Posted November 24, 2006 Share Posted November 24, 2006 [quote="PHP - Manual"]If you only want to determine if a particular needle occurs within haystack, use the faster and less memory intensive function [url=http://www.php.net/strpos]strpos()[/url] instead.[/quote] Link to comment https://forums.phpfreaks.com/topic/28285-preg_match/#findComment-129359 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.