Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
479 views
in Technique[技术] by (71.8m points)

posix ere - Why is `ereg` deprecated in PHP?

Why is ereg deprecated in PHP?

I had a lot of functions which used this, now they always give warning.

What is the alternative of this too?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Ereg is deprecated because it was replaced by the the PCRE extension. The reason(s) it was replaced and deprecated is answered in the below link, but to save you some time here is the copy and pasted answer:

Note: preg_match(), which uses a Perl-compatible regular expression syntax, is often a faster alternative to ereg().

PHP ereg vs. preg

One difference between the two is that ereg looks for the longest matching result while preg looks for the first result. Here is the list of differences between the two to help you in determining how best to go about updating your code: http://www.php.net/manual/en/reference.pcre.pattern.posix.php

It should be of note that PHP 6.0 has COMPLETELY removed ereg, so if you are eventually going to be moving your code to a newer server that may use PHP 6.0, the ereg function will no longer be available.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...