5 Years
Discussion Span
Last Post by TySkby

How many comments do you allow per user per day? If only 1, you could be OK, if whatever somebody wants, that's a bit more difficult.

You could use a preg_match() to check for links as opposed to simply stripping them. If a link is in the post, reject it. Do these posts have unusual phrases in common (OK maybe an oxymoron)? Search for them and reject them.

Edited by diafol: n/a


I've never heard of this preg_match(). How would I use this?


Definitely check out this link for extra info on usage and syntax: http://php.net/manual/en/function.preg-match.php

Using this will require a bit of knowledge of regex (REGular EXpressions), which can be a pain and confusing at first, but definitely good to be familiar with, as regex can be used in many languages.

Essentially, using preg_match() will allow you to check a string for a matching pattern. For instance, you can search comments that people submit for a pattern that would be common to links, such as 'http://', 'www', '.com', etc. Then you can search for the pattern in the comment being posted and if it finds a match for something like 'http://somesite.com' or 'http://www.somesite.org' or anything like that (it depends on the regex you are searching for), you can either reject the post or replace the matching substring with some text like 'LINK REMOVED'.

Here are some good examples and resources to help you:

http://RegExLib.com is a great place to find already-written regular expressions that you can use in your code.

This is a regex pattern that will match valid URLs in a string. I found it here: http://regexlib.com/REDetails.aspx?regexp_id=25

Also, you may want to read the thread at http://stackoverflow.com/questions/1141848/regex-to-match-url. People have posted some good regex patterns to match what you are trying to do.

Hope that helps! Regex can be tough, but knowing it and/or knowing where to find examples are well worth it in the end.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.