php 已弃用:函数 eregi() 已弃用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18509858/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Deprecated: Function eregi() is deprecated in
提问by Jush
I'm trying to submit values to the database but i get an error message
我正在尝试向数据库提交值,但收到一条错误消息
Deprecated: Function eregi() is deprecated in C:\wamp\www\OB\admin_add_acc.php on line 20 and 27
已弃用:函数 eregi() 在 C:\wamp\www\OB\admin_add_acc.php 中的第 20 和 27 行已弃用
Here is the code:
这是代码:
<?php
include 'db_connect.php';
if(isset($_POST['Submit']))
{
$acc_type=ucwords($_POST['acc_type']);
$minbalance=ucwords($_POST['minbalance']);
if (!eregi ("^[a-zA-Z ]+$", stripslashes(trim($acc_type))))//line 20
{
echo "Enter Valid Data for Account Type!";
exit(0);
}
else
{
if (!eregi ("^[0-9 ]+$", stripslashes(trim($minbalance))))//line 27
{
回答by MisterBla
eregi()
is deprecated as of PHP 5.3, use preg_match()
instead.
eregi()
自 PHP 5.3 起已弃用,请preg_match()
改用。
Note that preg_match()
is only case insensitive when you pass the i
modifier in your regular expression.
请注意,preg_match()
仅当您i
在正则表达式中传递修饰符时才不区分大小写。
include 'db_connect.php';
if(isset($_POST['Submit']))
{
$acc_type=ucwords($_POST['acc_type']);
$minbalance=ucwords($_POST['minbalance']);
// Removed A-Z here, since the regular expression is case-insensitive
if (!preg_match("/^[a-z ]+$/i", stripslashes(trim($acc_type))))//line 20
{
echo "Enter Valid Data for Account Type!";
exit(0);
}
else
{
// \d and 0-9 do the same thing
if (!preg_match("/^[\d ]+$/", stripslashes(trim($minbalance))))//line 27
{
}
}
}
回答by vimist
From Wikipedia:
来自维基百科:
Deprecation is a status applied to a computer software feature, characteristic, or practice indicating it should be avoided, typically because of it being superseded.
弃用是一种应用于计算机软件功能、特性或实践的状态,表明它应该被避免,通常是因为它被取代了。
Take a look at the PHP manual for eregi. As you can see, it has the following warning:
查看eregi的 PHP 手册。如您所见,它有以下警告:
This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.
自 PHP 5.3.0 起,此函数已被弃用。非常不鼓励依赖此功能。
Further down the page there is some advice on what to use instead:
在页面下方有一些关于使用什么的建议:
eregi() is deprecated as of PHP 5.3.0. preg_match() with the i (PCRE_CASELESS) modifier is the suggested alternative.
自 PHP 5.3.0 起不推荐使用 eregi()。带有 i (PCRE_CASELESS) 修饰符的 preg_match() 是建议的替代方法。
So you can use the preg_matchfunction instead.
所以你可以改用preg_match函数。
回答by Deepu
You can find the answer here in the manual.Since its a Deprecated function in the php version you are using you will get that warning.Instead of ergi
you can use preg_match
.See the manual for preg match
您可以在手册中找到答案。因为它是您正在使用的 php 版本中的一个已弃用的函数,您将收到该警告。而ergi
不是您可以使用preg_match
.See the manual for preg match