Replace eregi with preg_match

My web hosting compnay has recently upgraded to php 5.3 and this has now thrown up a couple of errors in the code for some Joomla sites I have using a EzAutos plugin. The script uses eregi but this now needs replacing I believe with preg_match. I have one or two lines below, if someone can point me in the right direction I can hopefully resolve these issues.

if ( eregi( “bmp|gif|jpg|png”, $file )


		if (eregi("swf", $row-&gt;make_image)) {



		} elseif (eregi("gif|jpg|png", $row-&gt;make_image)) {


Mnay thanks


Start here:

Thanks for that. I have taken a look and do not fully understand how to make the changes, an example would be greatly appreciated

Dave :slight_smile:

if ( eregi( "bmp|gif|jpg|png", $file )

// can become

if ( preg_match( "/(bmp|gif|jpg|png)/i", $file )

Thanks very much for the example. I have changed the code and all errors are now gone.

Dave :smiley:

What exactly were you having trouble with? It’s no use being given code to copy and paste if you don’t know what the changes do.

The server has recently been upgraded to PHP 5.3 and the function eregi was deprecated. Looking at another post it was suggested that is should be replaced with preg_match? the error I was getting was as follows

Deprecated: Function eregi() is deprecated in /home/atouchof/public_html/administrator/components/com_ezrider/includes/class.ezrider.php on line 595


You told us that much already. After reading the page that I linked to earlier, were there any specific points which meant you couldn’t come up with a solution before SgtLegend gave one to you on a plate?

No there were no other specific points. Thanks for your help


So you just wanted spoon-feeding?

If that is how you would like to look at so be it! I asked for help and I was given it. We all have to start somewhere and I expect you did too. Is there a problem?

Absolutely, yes. But I’ll not push the point.

I am happy that you have “found” the solution to this individual problem. (:

To be honest I would rather hear your point? Ultimately I had to make more than one change anyway to a number of files.

Feel free to PM me or post here


OK here goes. The following is off-topic, but since the problem in the original post was solved I think we’re okay to have a few off-topic words.

First, a little background. Ever since the POSIX regular expressions extension, which contains functions like ereg(), was deprecated in PHP 5.3.0, the question of migrating existing code over to the recommended PCRE family of functions (preg_match() and friends) has popped up regularly. To this end, the special page was added to the PHP manual aimed at mentioning the most visible differences between the two regex flavours.

The fact that this question still comes up time and time again has me intrigued, can people just not find the manual page? Does the jargon on there just go over people’s heads, when they do find the page? Answering these kinds of questions is difficult, since usually people are asking “how do I make ereg(x) into preg_match(y)?” and the same pattern of events occurs as happened here: someone kindly points the OP at the relevant page of The Manual where all answers can be found (okay that might be stretching the truth a little, but we try), the OP replies with “huh, what?” and, here’s the kicker, another kind soul chips in with a copy/paste code snippet that the OP tries, notices it works, then skips away without anyone knowing whether they really learned something or will be back tomorrow with exactly the same question for a different regex. I’m still unsure whether you, Dave, are one of those people or the type to be taught how to fish.

Back to this thread again, after pointing you in the right direction (not everyone knows where to look for pre-existing documentation/support) the hope was that you would reply either having absorbed the information or come back with “that made no sense!” and you did (though it clearly made some sense, even if you were struggling and needed a hand). Then, the helpful person (we’ve all been this person) came along and offered a copy/paste snippet tailored solely for your individual problem piece of code, with no description/explanation of any kind. This would be fine had it been an example, as you had asked, to show the concepts that you need to learn when migrating your code. However because it was a drop-in replacement, you were left with the ability to say “awesome, thanks it works!” and we’re left, as I said before, wondering whether you’ll be back again tomorrow, scratching your head over a conceptually identical problem and, the ever-present danger, expecting a quick copy/paste answer. Now, multiply this by how many people ask questions on forums like this one, on mailing lists, IRC channels, and the other avenues of support and I hope you can see why I’d rather help to teach people to find their own answers, or at the very least point them, in the right direction, rather than give them a quick fix.

Forums like these are great, both for being taught (given the chance) and for being provided with quick fixes. It’s just a shame that, in my opinion, too much of the latter steps on the toes of the former even if the OP would be a willing student if given the time to be one.

P.S. Sorry for airing the above here, but you did ask. (:

P.P.S. If you have any feedback on that particular page of the manual from a “first time reader” point of view, I would love to hear it. The manual is there for folks like you to learn from so any feedback and improvements are super-welcomed. Fire over a PM if you do.

Sorry it has taken me so long to reply :wink:

I am always willing to learn and to that end I have recently signed up to a Sitepoint course for PHP & MySql which I am sure will provide me with a greater understanding.

The situation I faced when asking that question wasn’t adversley affecting the site and was only appearing within the admin control panel. I wanted to get it corrected ASAP and that is why I took the quick fix answer at that time. As noted above I always try to learn something however small from any solution I am provided with.

When you directed me to the manual I did not see a direct solution that related to images, so from that point of view I was probably looking for the immediately obvious. Sometimes though when you are very busy we all neglect to dig a little deeper.

Thanks for taking the time to reply both on your first post and the last.