jbcubed3 — 2014-01-12T05:46:38-05:00 — #1
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.
vectorialpx — 2014-01-13T08:46:02-05:00 — #2
preg_match_all('#[watch,stream](.+)online#', strtolower($str), $match);
var_dump( $match );
lemon_juice — 2014-01-13T10:48:38-05:00 — #3
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.
vectorialpx — 2014-01-13T15:38:19-05:00 — #4
Ouch! I messed up the parentheses types (must confess I'm not a regExp expert).