-2

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...

mip
  • 8,355
  • 6
  • 53
  • 72
user3304633
  • 27
  • 1
  • 7
  • "*It is not working*" is not useful. Please explain, if you get an error message (if so, which one) or if the results differ from your expectation (if so, how). – Amal Murali Feb 18 '14 at 12:27
  • What is your question. What output are you expecting.. Can you provide an example – 웃웃웃웃웃 Feb 18 '14 at 12:28
  • From your comment it seems that you want to avoid anything but numbers. Is this a case? Please explain what do you expect from that `a5efa5` id - is this valid or invalid? – mip Feb 18 '14 at 13:07

2 Answers2

1

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.

Pattle
  • 5,983
  • 8
  • 33
  • 56
  • If feature is deprecated that does not mean that it will not work. – mip Feb 18 '14 at 12:49
  • And there are much better questions/answers covering the deprecation of ereg_*: http://stackoverflow.com/q/6270004/46675 – Mike B Feb 18 '14 at 13:06
1

Use preg_replace

$id = preg_replace('#[^a-z0-9]+#', '', $id);
LONGMAN
  • 980
  • 1
  • 14
  • 24