Created
January 18, 2010 03:20
-
-
Save anonymous/279756 to your computer and use it in GitHub Desktop.
find needle array in haystack string
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
// 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