Skip to content

Instantly share code, notes, and snippets.

@alancoleman
Created March 13, 2014 09:41
Show Gist options
  • Save alancoleman/9525203 to your computer and use it in GitHub Desktop.
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.
<?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