php 函数 ereg() 已弃用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4297501/
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
Function ereg() is deprecated
提问by narayanpatra
I have started to learn PHP. So installed WAMP server on my windows 7 machine. I am trying the following PHP code :
我已经开始学习PHP。所以在我的 Windows 7 机器上安装了 WAMP 服务器。我正在尝试以下 PHP 代码:
<?php
$phrase = "I love PHP";
if (ereg("PHP", $phrase)) {
echo "The expression matches";
}
?>
When tried this in my mozilla, I got the output :
在我的 mozilla 中尝试这个时,我得到了输出:
Deprecated: Function ereg() is deprecated in C:\wamp\www\learnphp\common.php on line 3
The expression matches
I think the code is correct. I can't understand the error. Can anybody explain me what this "Deprecated" means here? and how to solve this error?
我认为代码是正确的。我无法理解错误。任何人都可以向我解释这里的“已弃用”是什么意思?以及如何解决这个错误?
My php version is 5.3.0. can it be version problem?
我的 php 版本是 5.3.0。会不会是版本问题?
EDIT : I googled it and found something about include\file.inc file in www folder. I don't have include directory in my www folder.
编辑:我用谷歌搜索并在 www 文件夹中找到了一些关于 include\file.inc 文件的信息。我的 www 文件夹中没有包含目录。
回答by VoteyDisciple
"Deprecated" means that PHP 5.3.0 no longer supports that function.
“已弃用”意味着 PHP 5.3.0 不再支持该功能。
You should treat ereg()as not existing anymore.
您应该将ereg()视为不再存在。
The function does still exist, but only to support existing applications where it's been used.
该功能仍然存在,但仅用于支持使用过它的现有应用程序。
When writing new code, never use a deprecated function.
编写新代码时,切勿使用已弃用的函数。
Instead, consider the preg_matchfunction.
相反,请考虑preg_match函数。
回答by Gordon
Deprecated means this function will eventually be removed from PHP in a future version. You should no longer rely on it in your code and instead use the suggested alternative.
弃用意味着此功能最终将在未来版本中从 PHP 中删除。您不应再在代码中依赖它,而应使用建议的替代方案。
In case of PHP's ereg
, heed the notice in the PHP Manual:
如果是 PHP ereg
,请注意 PHP 手册中的注意事项:
As of PHP 5.3.0, the regex extension is deprecated in favor of the PCRE extension. Calling this function will issue an E_DEPRECATED notice. See the list of differencesfor help on converting to PCRE.
从 PHP 5.3.0 开始,regex 扩展已被弃用,取而代之的是 PCRE 扩展。调用此函数将发出 E_DEPRECATED 通知。有关转换为 PCRE 的帮助,请参阅差异列表。
Also see the description of E_DEPRECATED
in the PHP Manual.
For all deprecated features in PHP5.3, see Deprecated features in PHP 5.3.x.
For more general information see the Wikipedia article on Deprecation in Software
另请参阅E_DEPRECATED
PHP 手册中的说明。
有关 PHP5.3 中所有弃用的功能,请参阅PHP 5.3.x 中的弃用功能。
有关更多一般信息,请参阅维基百科关于软件中的弃用的文章
回答by Micheal Hymanson the 15th
It means that the function you are using is now obsolete. You cannot use this function any more. I received the same error with PHP 5.5.6. One possible solution to your issue could be to downgrade your PHP version so it gets supported.
这意味着您正在使用的功能现已过时。您不能再使用此功能。我在 PHP 5.5.6 中收到了同样的错误。您的问题的一种可能解决方案是降级您的 PHP 版本以使其得到支持。