0

I was making a contact form again and eregi() is being used on it. But as we all know, the eregi() function has been deprecated on PHP 5.3 so I want to know what alternative function/s can I use to replace the function eregi()? I've tried !preg_match and even though I get the desired output, there appears to be an error still! >3<

Warning: preg_match(): Delimiter must not be alphanumeric or backslash in C:\xampp\htdocs\Wall\mailform.php on line 38 (Possible spam attempt detected. If this is not the case, please edit the content of the contact form and try again.) - The sentence inside the () is the desired result.

This is the codes I used. !preg_match() used to be eregi(). :)

function spamcheck($field) {
    if(!preg_match("to:",$field) || !preg_match("cc:",$field) || !preg_match("\r",$field) || !preg_match("\n",$field) || !preg_match("%0A",$field)){ 
        $possiblespam = TRUE;
    }else $possiblespam = FALSE;
    if ($possiblespam) {
        die("Possible spam attempt detected. If this is not the case, please edit the content of the contact form and try again.");
        return 1;
    }
}

Thank you to whoever is going to answer and help me. Any kind of help is very much appreciated!

powtac
  • 40,542
  • 28
  • 115
  • 170
  • From your "regular expression"s, do you simply want `stripos`? – Passerby Jan 07 '13 at 07:31
  • TBH, I don't know what the regular expressions were and I'm too lazy to study because I'm in a hurry. What's 'stripos', btw? I've searched through the net and most answers were I should use !preg_match. But there's an error when I use it. – Micaela Grace Osete Jan 07 '13 at 08:23
  • It seems you only want to know if e.g. "to:" exists in `$field`. If that's true, then it doesn't need RegExp at all. Try `if(stripos($field,"to:")!==false || stripos($field,"cc:")!==false)`. – Passerby Jan 07 '13 at 08:55

1 Answers1

1

You have to surround the regexes with delimiters:

preg_match("/to:/",$field)
     here __^   ^
Toto
  • 89,455
  • 62
  • 89
  • 125