Skip to content

Instantly share code, notes, and snippets.

@necenzurat
Last active December 29, 2015 10:59
Show Gist options
  • Save necenzurat/7660760 to your computer and use it in GitHub Desktop.
Save necenzurat/7660760 to your computer and use it in GitHub Desktop.
<?php
function exclude($needle, $haystack){
foreach ($haystack as $element) {
$pattern = "/".$element."/";
preg_match($pattern, $needle, $matches);
var_dump($matches);
if ($matches)
return TRUE;
else
return FALSE;
}
}
$array = array("facebook", "yahoo", "google.mx", "yahoo");
var_dump(exclude("google.mx", $array));
var_dump(exclude("facebook.com", $array));
var_dump(exclude("x.ro", $array));
var_dump(exclude("mail.yahoo.com", $array));
var_dump(exclude("google.ro", $array));
var_dump(exclude("google.it", $array));
var_dump(exclude("google.co.uk", $array));
var_dump(exclude("google.co.uk", $array));
//preg_match("/^google/i", "google.com", $matches);
//var_dump($matches);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment