Check if string contains a value in array [duplicate]

Try this.

$string = 'my domain name is website3.com';
foreach ($owned_urls as $url) {
    //if (strstr($string, $url)) { // mine version
    if (strpos($string, $url) !== FALSE) { // Yoshi version
        echo "Match found"; 
        return true;
    }
}
echo "Not found!";
return false;

Use stristr() or stripos() if you want to check case-insensitive.

Leave a Comment