0

I am new to php, how do i change eregi from preg_match using this script:

if(!eregi("^select",$sql))
    {
        echo "wrongquery<br>$sql<p>";
        echo "<H2>Wrong function silly!</H2>\n";
        return false;
    }

is it like this: if(!eregi("/^select/i",$sql))

thank you

  • if(!preg_match("%^select%i",$sql)) – sinisake Jul 18 '13 at 01:12
  • possible duplicate of [How can I convert ereg expressions to preg in PHP?](http://stackoverflow.com/questions/6270004/how-can-i-convert-ereg-expressions-to-preg-in-php) – mario Jul 18 '13 at 01:15

2 Answers2

2

Use this:

if (!preg_match ("/^select/i", $sql))
{
    // do something...
}
Michal
  • 3,584
  • 9
  • 47
  • 74
2

don't use regex for simple search of string, you can use one of the following:

$query = "select * from";
$keyword = "select";
if(strpos($query, "select") === 0){
 echo "found";
}
if(substr($query, 0, strlen("select")) === "select"){
 echo "found";
}