Being plagued with annoying spam over the last few weeks on my forums and looking to build a quick function to detect strings that look like this:
Watch (*) Online
Stream (*) Online
So if the post string = $post_text - are there any code examples as to how I could use preg_match_all to detect it - if $post_text contains at least one instance of the above, then do this.
preg_match_all('#[watch,stream](.+)online#', strtolower($str), $match);
var_dump( $match );
The square bracket group means any character within the bracket selection so you are basically eliminating any words containing those letters and a comma!
This should work better and preg_match (without all) should be suffictient:
$match_exists = preg_match('#(watch|stream).+?online#i', $str);
This will match these strings:
buy watch online now!
WATCH any text here provided it's in one line(!) ONLINE
best streaming online
If you want to also catch cases when the two words are in different lines then add the 's' modifier to the end of the regex.
Ouch! I messed up the parentheses types (must confess I'm not a regExp expert).
This topic is now closed. New replies are no longer allowed.