Does this work for you? I think you'll have to modify this in the future but for a rough implementation (what you've asked for) it should work. I also presumed your "check out my" is required text if not that can be removed. The \s*
means any amount of whitespace; the \w*
means any number of word characters (a-z, 0-9, and/or underscore). The |
means "or" and the ()
groups the two values that "or" should be affecting. If you have questions please ask. The outer most parenthesis group the potential domain. You may want to alter the \w*
to \w+
but I'd presume if they're saying "check out my .com" you'd also want to filter it...
if(preg_match('~check\s*out\s*my\s*(\w*\s*(\.|dot)\s*com)~i', $input, $domain)) {
echo 'This is spam?';
}
A solution based on your actual code:
<?php
$spamCount=0;
$input=preg_replace(array('~\s*~', '~dot~i'), array('', '.'), 'Hi. Please see my website at "test domain . com" (no spaces) anothertest dot com');
$checkTheseDomains = array("testdomain.com","anothertest.com");
foreach($checkTheseDomains as $domain) {
if(strpos($input, $domain) !== false) {
$spamCount++;
}
}
if($spamCount > 0){
echo "Spam count of <b>".$spamCount."</b>";
}else{
echo "No spam";
}