Created
March 13, 2014 09:41
-
-
Save alancoleman/9525203 to your computer and use it in GitHub Desktop.
Check to see if a string contains any substring values from an array. The first instance will be returned with a message.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$searchstring = "Alan Coleman is Grrrrate!"; | |
$arraycheck = array("\*", "!", "@", ",", "%"); | |
if (preg_match('/'.implode('|', $arraycheck).'/', $searchstring, $matches)) { | |
echo("Fail, the string '{$matches[0]}' was found in the search string."); | |
} else { | |
echo("Pass, None of the strings in the array were found in the search string."); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment