Forked from anonymous/find needle array in haystack string
Created
January 18, 2010 03:31
-
-
Save robmorgan/279761 to your computer and use it in GitHub Desktop.
This file contains 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 | |
// need a true/false return if a needle is found. | |
$haystack = "this is the haystack/string full of goodness needle 1 needle 2"; // haystack | |
$needles = array("needle 1", "needle 2", "needle 3"); // needles | |
foreach ($needles as $key => $val) { | |
if (strpos($haystack, $val)) { | |
// do something | |
echo 'found match'; | |
} else { | |
// do something else | |
echo 'no match'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment