PHP ereg_replace is not working correctly

111 views Asked by At

My id is a5efa5.

Code below replacing deprecated[?] [^a-z0-9] is not working. a5efa5 in an id in my database table.

//Connect to the database through our include 
include_once "database.php";
// Get the member id from the URL variable
$id = $_REQUEST['id'];
$id = ereg_replace("[^a-z0-9]", "", $id); // filter everything but numbers for security
if (!$id) {
    echo "Missing Data to Run";
    exit(); 
}

Help me friends, where did I make a mistake...

2

There are 2 answers

2
Pattle On

It could be because ereg_replace is deprecated. Below is what is stated on the php.net website

This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.

If you are using a version or PHP greater than 5.3.0 then it will not work.

3
LONGMAN On

Use preg_replace

$id = preg_replace('#[^a-z0-9]+#', '', $id);