Spam protection: detect html tags or match patterns

Hi,

This is what I can think of to detect spams from injecting into my database,

$SpamError = "Malicious code content detected. Your IP Number of ".getenv("REMOTE_ADDR")."has been logged.";

if (preg_match("/a href/i", "$message_content")) {
  $spam = true; 
  echo '<error message="'.$SpamErrorMessage.'"/>'; 
} 

the idea is to match if <a href> exist, if it does, then it is a spam.

what if I have more patterns that I want to check, like <img> tags? how should I rewrite this code?

preg_match(“/a href/i”, “$message_content”);

but I think the best way is to detect if there is any html tag exist, then it must be a spam. how do I write the code to detect html tags from the input…?

Many thanks,
Lau

Checking for “a href” is the completely wrong way. What if the spammer uses “a href” (notice a double space). What if a real user wants to put in a link?

Either use a markup for comments like BBCode/Markdown, or human-review everything.

I won’t help with the original question because your idea makes me angry.