PHP ereg_替换无法正常工作

PHP ereg_替换无法正常工作,php,regex,ereg-replace,Php,Regex,Ereg Replace,我的id是a5efa5 下面的代码替换不推荐的[?][^a-z0-9]无效a5efa5在我的数据库表中的id中 //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

我的id是
a5efa5

下面的代码替换不推荐的[?][^a-z0-9]无效<代码>a5efa5在我的数据库表中的id中

//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(); 
}

朋友们,帮帮我,我在哪里犯了错误…

可能是因为
ereg\u replace
是。下面是php.net网站上的说明

从PHP 5.3.0开始,此函数已被弃用。非常不鼓励依赖此功能

如果您使用的是大于5.3.0的版本或PHP,那么它将不起作用

使用preg_替换

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

“它不起作用”是没有用的。请解释,如果您收到错误消息(如果是,是哪一条),或者结果是否与您的预期不同(如果是,如何)。您的问题是什么。你希望得到什么样的产出。。你能提供一个例子吗?从你的评论来看,你似乎想避免数字以外的任何东西。是这样吗?请解释一下你对该
a5efa5
id的期望-这是有效的还是无效的?如果该功能被弃用,并不意味着它将不起作用。还有更好的问题/答案涵盖了ereg的弃用:它不接受表中的这个a5efa5 id orry,我的代码中有bug,我更新了我的帖子,见上文,我同意这是正确的答案。