Jump to content

[SOLVED] Rewrite if(eregi($bad_string, strtolower($str_to_test))) using "preg_match"


worldcomingtoanend

Recommended Posts

I tried to replace eregi with preg_match and I got this error;

Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in

 

But i am confused as to how to write the delimiter part of it.  a more clearer code is here below:

foreach($bad_strings as $bad_string) {
    if(eregi($bad_string, strtolower($str_to_test))) {
      echo "$bad_string found. Suspected injection attempt - mail not being sent.";
      exit;

Depends on the content of bad strings, are they actually regex patters or just strings? If they are just strings...

 

<?php
foreach($bad_strings as $bad_string) {
   if(stristr($input, $bad_string)) {
      echo "$bad_string found. Suspected injection attempt - mail not being sent.";
      exit;
   }
}
?>

 

If they are infact regular expressions then you'd need to do something like...

 

<?php
foreach($bad_strings as $bad_string) {
   if(preg_match("~$bad_string~i", $input)) {
      echo "$bad_string found. Suspected injection attempt - mail not being sent.";
      exit;
   }
}
?>

Nb: Untested.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.