jaymc Posted November 24, 2006 Share Posted November 24, 2006 [quote]Here is my code<?php$string = "hi &?/\='\",%+ hi";$patterns[0] = "/&/";$patterns[1] = "/\?/";$patterns[3] = "/\//";$patterns[4] = "/\\\/";$patterns[5] = "/=/";$patterns[6] = "/'/";$patterns[7] = "/\"/";$patterns[8] = "/,/";$patterns[9] = "/%/";$patterns[10] = "/\+/";if (preg_match($patterns, $string)) {echo "YES";} else {echo "NO";}?>[/quote]Just wondering why I get an error when running that[i]Warning: preg_match() expects parameter 1 to be string, array given in /home/cff/public_html/testy.php on line 28NO [/i] Link to comment https://forums.phpfreaks.com/topic/28378-preg-match-if/ Share on other sites More sharing options...
brendandonhue Posted November 24, 2006 Share Posted November 24, 2006 Because the first parameter to preg_match should be a string and you're giving it an array. Link to comment https://forums.phpfreaks.com/topic/28378-preg-match-if/#findComment-129797 Share on other sites More sharing options...
jaymc Posted November 24, 2006 Author Share Posted November 24, 2006 IS their anyway I can use it with an arrayIf not, how do I set it out to check for each of those chars listed in the array Link to comment https://forums.phpfreaks.com/topic/28378-preg-match-if/#findComment-129804 Share on other sites More sharing options...
Psycho Posted November 24, 2006 Share Posted November 24, 2006 Separate each item with the pipe character "|". That represents OR. So if any of those items are found it will return true:[code]$patterns = "/&|\?|\/|\\\|=|'|\"|,|%|\+/";if (preg_match($patterns, $string)) {echo "YES";} else {echo "NO";}[/code] Link to comment https://forums.phpfreaks.com/topic/28378-preg-match-if/#findComment-129811 Share on other sites More sharing options...
jaymc Posted November 25, 2006 Author Share Posted November 25, 2006 Worked greatCheers Link to comment https://forums.phpfreaks.com/topic/28378-preg-match-if/#findComment-129835 Share on other sites More sharing options...
Ninjakreborn Posted November 25, 2006 Share Posted November 25, 2006 You can also run a foreach,a nd just use pregmatch on them one at a time, with a foreach statement Link to comment https://forums.phpfreaks.com/topic/28378-preg-match-if/#findComment-129838 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.