I have a long string, and an array of country names. So the array looks something like this:
array('Afghanistan', 'Bulgaria', 'United States', 'Bulgaria', ...)
You can use something like:
$country_names = array('Afghanistan', 'Bulgaria', 'United States', ...); $country_names_preg = "/(" . implode("|", $country_names) . ")/"; preg_match_all($country_names_preg, $long_string, $matches); //$matches will contain all of the country matches. $echo "found: " . implode(", ", $matches); // There would ideally be a check to make sure that $matches had something in it!