Old regular expression function in PHP that is now DEPRECATED in favour of preg_match()
Questions tagged [ereg]
59 questions
151
votes
4 answers
How can I convert ereg expressions to preg in PHP?
Since POSIX regular expressions (ereg) are deprecated since PHP 5.3.0, I'd like to know an easy way to convert the old expressions to PCRE (Perl Compatible Regular Expressions) (preg).
Per example, I have this regular expression:
eregi('^hello…

netcoder
- 66,435
- 19
- 125
- 142
34
votes
6 answers
Function ereg_replace() is deprecated - How to clear this bug?
I have written following PHP code:
$input="menu=1&type=0&";
print $input."
".ereg_replace('/&/', ':::', $input); After running above code, it gives following warning, Deprecated: Function ereg_replace() is deprecated How can I resolve this…
".ereg_replace('/&/', ':::', $input); After running above code, it gives following warning, Deprecated: Function ereg_replace() is deprecated How can I resolve this…

Pradip
- 1,317
- 4
- 21
- 36
25
votes
2 answers
Troubleshooting "Delimiter must not be alphanumeric or backslash" error when changing ereg() to preg_match()
Possible Duplicate:
Converting ereg expressions to preg

robpal
- 846
- 4
- 10
- 21
8
votes
4 answers
Expected lifespan of ereg, migrating to preg
I work on a large PHP application (>1 million lines, 10 yrs old) which makes extensive use of ereg and ereg_replace - currently 1,768 unique regular expressions in 516 classes.
I'm very aware why ereg is being deprecated but clearly migrating to…

Oliver Emberton
- 951
- 4
- 14
7
votes
3 answers
PHP - preg_match and "Unknown modifier" error
I had that test that worked fine :
if (ereg("([0-9]{2})[-./]([0-9]{2})[-./]([0-9]{4})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})", $dateToTest, $tab) == false)
and as ereg is deprecated, I have replaced that test with this one :
if…

Oliver
- 23,072
- 33
- 138
- 230
5
votes
3 answers
Deprecated: Function ereg() is deprecated
Possible Duplicate:
How can I convert ereg expressions to preg in PHP?
My contact form is othervise working but I keep getting the following
error:
Deprecated: Function ereg() is deprecated in/home/.....
I'm really lost here but I figure this…

no0ne
- 2,659
- 8
- 28
- 44
5
votes
2 answers
4
votes
6 answers
How to check if string contains only specified character set?
I'm working on string and I wonder which way is best to check if string contains only specified character set:
@ ∆ SP 0 ¡ P ¿ p
£ _ ! 1 A Q a q
$ Φ " 2 B R b r
¥ Γ # 3 C S c s
è Λ ¤ 4 D T d t
é O % 5 E U …

arekstasiewicz
- 383
- 2
- 11
- 24
4
votes
1 answer
Fatal error: Uncaught Error: Call to undefined function ereg()
I am using php v7.3.2 on Centos 7.6.
Before upgrading php the version was 5.4.
In v 5.4 i had no errors.
But in v 7.3.2 i got this error :
Fatal error: Uncaught Error: Call to undefined function ereg() in
…

SilverLight
- 19,668
- 65
- 192
- 300
4
votes
2 answers
ereg() to preg_match() how?
I have kind of simple regexes that i am using.
It's so simple as:
"user/"
"user/[A-z0-9_-]"
These all work fine with ereg, but not preg.
How to convert it?
Thanks

Lars Hansen
- 105
- 1
- 5
3
votes
2 answers
Need some help upgrading a tiny piece of ereg_replace
I have this line of code I use for SEO purposes. The only thing is that it has an ereg_replace function in it. Now I get "ereg_replace() is deprecated" error.
Apparently it's not as simple as switching it to preg_replace and my RegEx-fu is not too…

Serhiy
- 2,505
- 3
- 33
- 49
2
votes
1 answer
Error updating ereg call to use preg_match instead
I'm trying to convert the following ereg() call to use preg_match() instead:
if (ereg('(.*/)(.*)$',$fileref,$reg) ) {
This is the preg_match() call I'm attempting to replace it with:
if (preg_match('(.*/)(.*)$',$fileref,$reg) ) {
When I…

AlunR
- 455
- 3
- 10
2
votes
3 answers
How can I allow only 2 dots after @ in email validation php using ereg
I am trying to validate email in php using ereg, where I am not allowed to enter more than two dots after @ and it can't begin with any special character, how can I do it.
function chk($a)
{
$pattern = "^([A-Za-z0-9\.|-|_]{1,60})([@])";
$pattern…

Hunterr
- 553
- 1
- 8
- 28
2
votes
1 answer
Replacing ereg_replace()
I have some legacy code I'm trying to update to run on PHP 5.4:
$row['subject'] = ereg_replace('[\]', '', $row['subject']);
I know I have to replace this with preg_replace, but since I've never used ereg, I'm not sure what this actually does.
Is…

Noodles
- 900
- 4
- 14
- 30
1
vote
1 answer
Php ereg validating a form
Im validating a form and its easy to validate numbers, letters a-z and so on but when i got to the point where i need to validate a field which must contain only the characters (a-z and special characters such as öçğüiş) with at least one space only…

London Boy
- 387
- 1
- 4
- 14