If your $string
is always consistent (ie. the domain name is always at the end of the string), you can use explode()
with end()
, and then use in_array()
to check for a match (as pointed out by @Anand Solanki in their answer).
If not, you'd be better off using a regular expression to extract the domain from the string, and then use in_array()
to check for a match.
$string = 'There is a url mysite3.com in this string';
preg_match('/(?:http:\/\/)?(?:www.)?([a-z0-9-_]+\.[a-z0-9.]{2,5})/i', $string, $matches);
if (empty($matches[1])) {
// no domain name was found in $string
} else {
if (in_array($matches[1], $owned_urls)) {
// exact match found
} else {
// exact match not found
}
}
The expression above could probably be improved (I'm not particularly knowledgeable in this area)