Skip to content

Instantly share code, notes, and snippets.

Created January 18, 2010 03:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/279756 to your computer and use it in GitHub Desktop.
Save anonymous/279756 to your computer and use it in GitHub Desktop.
find needle array in haystack string
// need a true/false return if a needle is found.
// Check for cookie before looking for needle. Saves some cpu
if (isset($_COOKIE["needle"]) && ($_COOKIE["needle"] != "0")) {
// cookie exist and is set correctly, now do stuff
} else {
$haystack= "this is the haystack/string full of goodness"; // haystack
$needles = array("needle 1","needle 2","needle 3"); // needles
foreach ($needles as $key => $val){
if (stripos($haystack, $val)){
setcookie(needle, found, time()+100); // set found cookie
echo "FOUND";
} else {
setcookie(needle, notfound, time()+100); // set not found cookie
echo "NOT FOUND";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment