IT IS HERE! Get Smashing Node.JS on Amazon Kindle today!
Show Posts
← Back to homepage

If you upgraded to PHP 5.3, chances are high you’re going to run into a few warnings or deprecated function messages.
An example is the ereg family of functions, which are gone for good, as they were slower and felt less familiar than the alternative Perl-compatible preg family.

To migrate ereg():

ereg('\.([^\.]*$)', $this->file_src_name, $extension);

becomes

preg_match('/\.([^\.]*$)/', $this->file_src_name, $extension);

Notice that I wrapped the pattern (\.([^\.]*$)) around / /, which are RegExp delimiters. If you find yourself escaping / too much (for an URL for example), you might want to use the # delimiter instead.

To migrate ereg_replace():

$this->file_dst_name_body = ereg_replace('[^A-Za-z0-9_]', '', $this->file_dst_name_body);

becomes

$this->file_dst_name_body = preg_replace('/[^A-Za-z0-9_]/', '', $this->file_dst_name_body);

Again, I just added delimiters to the pattern.
If you are using eregi functions (which are the case-insensitive version of ereg), you’ll notice there’re no equivalent pregi functions. This is because this functionality is handled by RegExp modifiers.

Basically, to make the pattern match characters in a case-insensitive way, append i after the delimiter:

eregi('\.([^\.]*$)', $this->file_src_name, $extension);

becomes

preg_match('/\.([^\.]*$)/i', $this->file_src_name, $extension);

183 Comments

Kevin said

I’ve found that almost anything can be used as a delimiter with preg_match. I personally use ~ as I use it the least.

Kevin said

I’ve found that almost anything can be used as a delimiter with preg_match. I personally use ~ as it’s the least used character in my regex patterns.

Many thanks for this! I was up late doing a server migration, figured I’d upgrade to PHP 5.3… and of course I break one of my online stores, http://ambermariebently.com. Your fix saved me at 2am, I owe you big time I think:)

berong said

GREAT!GREAT!GREAT!

Manta said

Thanks worked well

Esck21 said

Thanks!

Juls said

Many thanks for that, seems to have fixed 80% of my problems – only ones it doesn’t seem to fif is where ereg(‘^’ ) occurs replacing as you say produces a: Warning: preg_match() [function.preg-match]: Unknown modifier ‘a’ in…

But that’s in admin – I can live with that for a while as long as the front end work ;) Thank you

    Did you manage to fix this problem in admin?? Its giving me big problems.
    Thanks!

Jason said

Thanks, excellent post. I would have expected this to show up on the php doc page for eregi, I guess they want you to figure it out yourself!

Alain said

Clear Fix For NeverEnding Programmings !

What’s happen with split function deprecated too ?
veru simple : split() change for explode() in same conditions

Prashanth said

Hi thank u very much, it helped me a lot………

Christian Alexis said

Thanks!! Really!! I Luv U!!!

Jonathan said

Thank you very much for this clear and simple explanation ! Much appreciated.

It’s worth noting that whilst ereg returns FALSE when there is no match, preg_match returns 0.

sudhakar said

A lot of thanks!!

Thanks alot its working. also i have a problem with split

Function split() is deprecated if you have any idea can u share with us

    Guillermo Rauch said

    Use explode().

nibuster said

thx!

Heath said

Thank you!

nibuster said

can’t resolve this one

$msg =ereg_replace(“(http|https|ftp|gopher|news)://([$ACCEPT_CHARS]+)”, “\\1://\\2” , $msg);

Angie said

Can I ask a really stupid question……what file am i supposed to edit? i cant find that code in the php.ini file. Am I being stupid??!!

    nibuster said

    doesen’t browser informs you about error when you test your project? it should say where error is. file and line no.

catalinux said

Hi.

Can you please tell me what should I change in the code below to make things work:
$check_url = str_replace(“\””, “”, $check_url);
if ((eregi(“]*script*\”?[^>]*>”, $check_url)) || (eregi(“]*object*\”?[^>]*>”, $check_url)) ||
(eregi(“]*iframe*\”?[^>]*>”, $check_url)) || (eregi(“]*applet*\”?[^>]*>”, $check_url)) ||
(eregi(“]*meta*\”?[^>]*>”, $check_url)) || (eregi(“]*style*\”?[^>]*>”, $check_url)) ||
(eregi(“]*form*\”?[^>]*>”, $check_url)) || (eregi(“\([^>]*\”?[^)]*\)”, $check_url)) ||
(eregi(“\””, $check_url))) {

I got this error:
Deprecated: Function eregi() is deprecated in E:\xampp\htdocs\laculprietenia\maincore.php on line 35

Deprecated: Function eregi() is deprecated in E:\xampp\htdocs\laculprietenia\maincore.php on line 35

Deprecated: Function eregi() is deprecated in E:\xampp\htdocs\laculprietenia\maincore.php on line 36

Deprecated: Function eregi() is deprecated in E:\xampp\htdocs\laculprietenia\maincore.php on line 36

Deprecated: Function eregi() is deprecated in E:\xampp\htdocs\laculprietenia\maincore.php on line 37

Deprecated: Function eregi() is deprecated in E:\xampp\htdocs\laculprietenia\maincore.php on line 37

Deprecated: Function eregi() is deprecated in E:\xampp\htdocs\laculprietenia\maincore.php on line 38

Deprecated: Function eregi() is deprecated in E:\xampp\htdocs\laculprietenia\maincore.php on line 38

Deprecated: Function eregi() is deprecated in E:\xampp\htdocs\laculprietenia\maincore.php on line 39

Thank you.

Se Ri said

Hi, thanks for your writing. I fixed almost all deprecations as your guide, but except this code:

if (preg_match(‘^’.$arrParam[0].’=’, $value))

When I put / / as delimiter before and after ^ to become:

if (preg_match(‘/^/’.$arrParam[0].’=’, $value))

I keep getting error as:

Unknown modifier ‘r’ in C:/Program Files/EasyPHP5.3.0/www/taskfreak/include/classes/tzn_generic.php

Note: tzn_generic.php is the file I put above code.

Please help me.

Many thanks,
Seri

nickstr said

what about this

if (isset($_SERVER['HTTP_HOST']) AND isset($_SERVER['HTTP_REFERER'])) {
$visitorInfo['referer'] = (!eregi($_SERVER['HTTP_HOST'],$_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : “” ;
} else {
$visitorInfo['referer'] = “”;
}

navane said

Hi.. ereg() with preg_match() is working well

M H Rasel said

Great site. helps me a lot.

gilemon said

Thanks for this! It helped me writing a Perl script that find all these deprecated functions.
You can download the script here:
http://nthinking.net/index.html#reDeprec.html

garzanti said

A very usefull post, it saved my day. Thnx

b33z said

so, what would i edit to make this work properly:

elseif(!eregi(“http://”,$uri) && !eregi(“https://”,$uri))

anybody? im really stuck! thanks in advance

    Rodoprogramador said

    elseif(!preg_match(“#http://#i”,$uri) && !preg_match(“#https://#i”,$uri))

Markus said

Thanks, ymmd :)

josh_kg said

Thanks for this, fixed my problem after we upgraded PHP to 5.3 and our WordPress theme choked. Much appreciated!

M7md said

Thaaaaaaaaaaanks its working !

Goodwine said

Thanks for this post it’s just exactly what i was looking for

Bojic said

Hvala na postu!
Thank You for this post!
Very elegant solution!

Paulo said

Hi!

I use sql_regcase, that is is deprecated.

Did you know an sql_regcase alternative ?

Example (to remove sql syntax):
$string = preg_replace(sql_regcase(“/(from|select|insert|delete|where|drop table|show tables|#|\*|–|\\\\)/”),””,$string);

Thank you!

    Sorry for the newbie question…

    This is the answer:

    $string = preg_replace(“/(from|select|insert|delete|where|drop table|show tables|#|\*|–|\\\\)/i”,””,$string);

    This is because ‘sql_regcase’ just make the regular expression for case insensitive match, so… just put ‘i’ in the last ‘/’.

    Simple… but, why I don’t saw this before… :)

    Thank you very much!

ahmed morsy said

hi
i have appserv 2.6.0 and i setup oscommerce 2.2rc and i recive this error

Fatal error: Call to undefined function get_magic_quotes_gpc() in C:\AppServ\www\catalog\admin\includes\functions\compatibility.php on line 46

Sanjo said

Set the error reporting to E_ALL ^E_DEPRECATED where it is currently being set to E_ALL

change error_reporting(E_ALL); to
error_reporting(E_ALL ^E_DEPRECATED);

and everything will be perfect.

Helio said

I have this problem:

Function eregi() is deprecated in C:\xampp\htdocs\catalog\admin\file_manager.php on line 29

if (!eregi(‘^’ . DIR_FS_DOCUMENT_ROOT, $current_path)) $current_path = DIR_FS_DOCUMENT_ROOT;

How can i fix this?

Thanks

    The Geek! said

    Try this

    if (!preg_match(‘#^’ . DIR_FS_DOCUMENT_ROOT.’#i’, $current_path)) $current_path = DIR_FS_DOCUMENT_ROOT;

deni said

I have this problem

Deprecated: Function ereg() is deprecated in C:\xampp\htdocs\member.php on line 109

if (!ereg(“MSIE”,$_SERVER['HTTP_USER_AGENT']))

How can i fix this?

Glenn said

Installed osC 2.2 on web server and went fine. To develop locally, I installed XAMPP on local computer, then installed osC 2.2 locally and got this error. Great post, easy to follow, fixed my problem!

I’m having troubles using preg_match() on a constant.
How to convert this old line? BASEURL is a constant.

eregi(BASEURL, $_SERVER['HTTP_REFERER'])

Ray said

We had a similar issue, but our ereg was comparing the contents of a variable to something else – ereg($AllowedTypes,getExt($sFileName). I found a workaround that may help alot of people here…

What preg_match (the replacement for ereg) is looking for is delimiters around the value. THis works great, unless you have a variable that’s used elsewhere and changing the value won’t work.

What I did was to write the line as such:

preg_match(“#”.$AllowedTypes.”#”,getExt($sFileName)

effectively enclosing the value in #s as the delimiter. BTW – the ‘/’ is not the required delmititer, it can be just about anything, as long as it’s the same on both ends. Adding the # front and back did the trick. A hack? Yeah, probably, but it does work. Saved my ass, for sure.

    Guillermo Rauch said

    FTA: “Notice that I wrapped the pattern (\.([^\.]*$)) around / /, which are RegExp delimiters. If you find yourself escaping / too much (for an URL for example), you might want to use the # delimiter instead.”

nekomata said

Thanks for this page. It is really clear.

Harsh said

Thanx alot its very helpful

Nice topic . Thank you for posting it !

    kisuina said

    Tui ki bojis nice topic ar ?

shafi said

Deprecated: Function eregi() is deprecated in C:\wamp\www\memories-on-gold\includes\classes\language.php on line 87 any one help me.

kabir said

Not working your eregi(). It is your false statement. Don’t write this in future. OKAY ?

Nice post, it was useful to fix ereg deprecated warnings in oscommerce, thank you

Pratik said

Hi… that was really a helpfull post.. Thnx… :)

oskar said

couldnt match with your solution
any help?

if (!eregi(“(^\.\.?)”, $file)) {

heroine said

Warning: strtoupper() expects parameter 1 to be string, array given in D:\xampp\htdocs\……\libraries\joomla\environment\request.php on line 97

can anyone help how to remove this warning….

Thank you for neat explanation how to fix the problem.

    sasa said

    sasasa

Thanks, very useful information.! i have some issue with deprecated syntax in php and need to replace it one by one. fiuh..

vasu said

hi, thanks.usefull info

David said

Hola, tengo este código y no se qué cambiar para que funcione:
if (eregi(‘^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$’, trim($s), $r))

Muchas gracias.

rizky said

Thankss alot that help fully

zynkmaster said

coll. nice dara man

techicore said

great thanks for this tricks

Tomas said

Hello I have this function but somehow I cannot get it working with preg_match can you please point me to sollution or write it here.
if (eregi($Match, $_SERVER['HTTP_USER_AGENT']))
Thanks

    Tomas said

    Solved i had to insert single quotes:
    if (preg_match(‘/$Match/i’,$_SERVER['HTTP_USER_AGENT']))

Tomas said

Damn it doesn’t work I didn’t notice it because the error wasn’t displayed anymore but it returned wrong result

Tomas said

If someone is having the same problem the solution weren’t single quotes but DOUBLE “”

psychic said

very complex stuff but thank you for trying to make sense out of this error

sas said

sasasa

Bart said

Thank you very much, just what i needed.

that’s excellent thanks a lot!!!

Kevinjamesus86 said

Exactly what I was looking for, thank you.

Thanks! I’ve read a few different explanations of this, but yours is probably the clearest for a mostly front-end developer sort of person like me. Also, really nice blog theme.

Kukuludan said

Brothers and sisters I strongly need your help before I quite to learn php and its staff. I am very beginner and I am now in the middle of taking php video tutorial. Then I download phpMailer2.3 as my video tutor explained then I did exactly as my tutor explained to me to do. Finaly what I got are the followings
Deprecated: Function eregi() is deprecated in C:wampwwwphoto_galleryincludesphpMailerclass.phpmailer.php on line 599

Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:wampwwwphoto_galleryincludesphpMailerclass.smtp.php on line 122

Warning: fsockopen() [function.fsockopen]: unable to connect to smtp1.example.com:25 (php_network_getaddresses: getaddrinfo failed: No such host is known. ) in C:wampwwwphoto_galleryincludesphpMailerclass.smtp.php on line 122

Deprecated: Function eregi() is deprecated in C:wampwwwphoto_galleryincludesphpMailerclass.phpmailer.php on line 599

Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:wampwwwphoto_galleryincludesphpMailerclass.smtp.php on line 122

Warning: fsockopen() [function.fsockopen]: unable to connect to smtp2.example.com:25 (php_network_getaddresses: getaddrinfo failed: No such host is known. ) in C:wampwwwphoto_galleryincludesphpMailerclass.smtp.php on line 122
Message could not be sent.
Mailer Error: SMTP Error: Could not connect to SMTP host.
so can I get anyone helping me to get my mistake and teach me to know better

Ferox said

As clear as water :)
Thanks

Mithu said

Excellent! This help me a lot.

nhoj said

how that code work?

i try this code but no effect,,
anybody could help me?
eregi (“@.()+_*^%$#.[;]“, $branchname)
should i declare them one by one?

    Leo said

    Try this:
    preg_match(‘/@.()+_*^%$#.[;]/i’, ‘your_second_arument’, $branchname)

J.v.C said

thanks for information, great post!

Macdara said

Cheers, that makes sense!

thanks! very useful

Dej said

hi,
How to change ereg($startreg['format'], $date, $regs);
preg_match(‘/$startreg['format']/’, $date, $regs); is not working

    Buki said

    maybe try to this

    preg_match(‘/’.$startreg['format'].’/’, $date, $regs);

    or
    $text = ‘/’.$startreg['format'].’/’;
    preg_match($text, $date, $regs);

    Bipul said

    Hi,

    This will work. I also had the same problem (SugarCRM), found this one in latest version, replaced where it was not working, and get it sorted.

    preg_match(‘@’.$startreg['format'].’@’, $date, $regs);

Buki said

Thanx a lot!

Latvian said

how to change:

function mysql_modified_rows () {
$info_str = mysql_info();
$a_rows = mysql_affected_rows();
ereg(“Rows matched: ([0-9]*)”, $info_str, $r_matched);
return ($a_rows < 1)?($r_matched[1]?$r_matched[1]:0):$a_rows;
}

    FSA said

      function affected_rows(&$link) {
        $strInfo = mysql_info($link);
        $intRows = mysql_affected_rows($link);

        if (!$intRows) {
          preg_match(‘/Rows matched: (d*)/’, $strInfo, $matches);
          $intRows = intval($matches[1]);
        } // if

        return $intRows;
      } // function affected_rows

Maisegapmay said

Whatever, it helps me!

Vanil4 said

wow so helpful
thanks

Cornel said

Hi, I find your article very useful. However, as I am an amateur, i couldn’t fix this lines:
if( ! ereg(“^[A-Z0-9]+$”, $cf) ){
if( ! ereg(“^[0-9]+$”, $piva) ) {
Could you help me please?
Thank you in advance.
Best regards,
Cornel

    Cornel said

    Hi again,
    I come again to thank you very much for your post. I read it more carefully and based on your indications I fixed the lines.
    Thanks again and good luck.
    Cornel

Hungnm_54 said

how to change
eregi(“^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4})$”, $email)
if (!ereg(“^[0-9]+/[0-9]+/[0-9]{2,4}”,$sinhnhat))

Lele said

Merci Beaucoup

Rumbin said

EXCELLENT !!!! Simple and usefull… just what i needed… THX

Thank you!

    Testdomain said

     jhhhj

Ms_newy said

How can i fix this:

if(preg_match(‘.+.[jJ][pP][eE]?[gG]$’, $arquivo)
 

    FSA said

    if (preg_match(‘/.jpe?g$/i’, $arquivo)

Sameer said

Can I Know How to Fix This 
if(eregi(‘No file(s) found for’, $result)) {

Clare said

good job! very helpfull!!

Kürşat said

Thank you very much for this useful information.

Bryan Cady said

Which file do I make the changes in?  I don’t see these lines in the existing timthumb.php file?  

Thanks
Bryan

tOm said

Hi, please How I change this function to new convert. eregi(‘.([^.]*$)’, $this->file_src_name, $extension);

tOm said

 Hi :-), eregi below I solved with this: preg_match(“/^” . rtrim(‘/’, $test) . “.*/i”, rtrim(‘/’, realpath($victim))))
but I don’t solve this convert:
$valid_extensions = ‘(.’ . implode(‘|.’, $CFG_image_valid) . ‘)$’;
 eregi($valid_extensions, $filename)              ‘

please help me

Asdf said

cut your co.ck

Vikram 26dabas said

Plz solve this i hv trouble in sloving this problem

Date :
Time :

subash said

i also had the same problem and i replaced the ereg with preg_match and got another error as “Warning: preg_match() [function.preg-match]: Unknown modifier ‘=’ ”  in the following line

if(preg_match(‘^([^=]*)=["']?([^"']*)["']?$’,$v,$a3))

can anyone plz help me…

Cristian O. Balan said

Hi,
I need to change that:

 if ($az_multibyte) {                    // Note this will still not work with some multi-byte character.                    // Solution is to exclude them from the headings using ignore option.                    $pos1 = mb_ereg_match(‘[[:upper:][:lower:][:digit:]]’, $in1['initial']);                    $pos2 = mb_ereg_match(‘[[:upper:][:lower:][:digit:]]’, $in2['initial']);                    //az_trace(“COMP:”.$in1['initial'].”:”.$in2['initial'].”: $pos1 : $pos2″);                } else {                                    $pos1 = ereg(‘[[:alnum:]]’, $in1['initial']);                    $pos2 = ereg(‘[[:alnum:]]’, $in2['initial']);                    //az_trace(“COMP:”.$in1['initial'].”:”.$in2['initial'].”: $pos1 : $pos2 : $az_nonalphaend”);                }

Some idea?

Nicole said

Exactly what I was looking for. It helped me a lot. Thank you!!!

Saqib Agha said

 Loved you post.. you are saving lives.

Giorgios said

Solved: explore …. Thks

Jeffshead said

How do I fix this:

!eregi(basename($_SERVER['PHP_SELF']), $fileName) && ereg(‘^[^./][^/]*$’, $fileName))

Novica said

if ( eregi( ‘index.php?’, $row->link ) ) {

                        if ( !eregi( ‘Itemid=’, $row->link ) ) {

                            $row->link .= ‘&Itemid=’. $row->id;
                        }

Novica said

How do I fix this:
if ( eregi( ‘index.php?’, $row->link ) ) {

                        if ( !eregi( ‘Itemid=’, $row->link ) ) {

                            $row->link .= ‘&Itemid=’. $row->id;
                        }

Pip Jones said

Thanks this was a useful guide.

Thank You in Advance said

Hello all

I have a deny array IP function like the following,
—————————————————–
$deny = array(“192.168.10.170″, “192.168.1.*”, “192.160.*”);

if(in_array($_SERVER['REMOTE_ADDR'],$deny)) {     // Exactly IP
     header(“Location: deny-exact-ip.htm”);
      exit();} else {     // Wildcard IPs     foreach($deny as $ip) {          if(!eregi($ip,$_SERVER['REMOTE_ADDR'])) {               header(“Location: deny-wildcard-ip.htm”);
    exit();                        }     }}
 header(“Location: ok.php”);
—————————————————–

Can anyone help.
Thank you very much in advance.

    Fiathdv said

    Hello. This Should work:

    $deny = array(“192.168.10.170″, “192.168.1.*”, “192.160.*”);

    if(in_array($_SERVER['REMOTE_ADDR'],$deny)) {     // Exactly IP
         header(“Location: deny-exact-ip.htm”);
         
    exit();} else {     // Wildcard IPs     foreach($deny as $ip)
    {          if(!preg_match(‘/’.$ip.’/i’,$_SERVER['REMOTE_ADDR'])) {              
    header(“Location: deny-wildcard-ip.htm”);
        exit();                        }     }}
     header(“Location: ok.php”);

Jeff X said

Can someone please help me with this one:

!eregi(basename($_SERVER['PHP_SELF']), $fileName) && ereg(‘^[^./][^/]*$’, $fileName))

Thank you :)

I’m wondering if there is way to simply not display the deprecated error notices??

A1A4A said

Mate thanks a lot !
You just saved hours of hard working for me !

Khansahib said

Thanks a lot Mate!!
you saved me today!!
Thanks.. :-)

spider said

you saved me!
another important thing is to replace \\1 with \${1} (I’ve found that out the hard way) :D

Nic said

Hi, just run in to this problem on a whole load of contact forms. Can someone please help with this:

$mailHeader .= “Message-ID: \r\n”;

Thanks loads!

Macquid said

Thank you very much!!! I’m less than a rank beginner in coding of any kind; but your clear “instructions” allowed me to replace ereg_replace() with preg_replace()after having my server updated from PHP 5.2.x to PHP 5.3.8. and therefore showing the usual error messages on many pages throughout my site.

Just one question… The pages seem to be loading slower now than they did before updating PHP. Is that a consequence of migrating to preg_replace ()?

thanks again and Friendly regards

Just one

henrik said

Deprecated: Function eregi() is deprecated in /mnt/webf/e2/35/53159135/htdocs/images/guestbook/include/funct_utiles.php on line 512

if (eregi(“^[a-z0-9]$”, $chr))

How do i fix this. ? i have tried alot but i not so good to php code yet

Robert said

My problem is this:
Deprecated: Function ereg() is deprecated in /var/www/vhost/meyersound.es/home/html/index.php on line 347

in index.php line 347 I have:
ereg( “([0-9]{2,4})-([0-9]{1,2})-([0-9]{1,2})”, $fecha, $mifecha);
$lafecha=$mifecha[3].”/”.$mifecha[2].”/”.$mifecha[1];
return $lafecha;
}

index opened with NetBeans

How i can fix?
Thanks

dalegsman said

try dis …

if (preg_match(“/^[a-z0-9]$/i”, $chr))

This is the best tutorial I found on the subject , try as much combinations as you can – It will be worth it.

peace .

yhel said

how could i fix this?help pls return eregi(“^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$”, $email);

arif said

thanks…it works…awesome…

creative said

it’s working….

Brian said

running into an issue… trying to convert these three lines.

$request = ereg_replace (‘^/’, ”, $request);
ereg(‘([0-9_\./?]+)’, $request, $idmatch);
$request = ereg_replace(‘^/’, ”, $idmatch[1]);

Converted to:
$request = preg_replace(‘#^/#’, ”, $request);
preg_match(‘#([0-9_\./?]+)#’, $request, $idmatch);
$request = preg_replace(‘#^/#’, ”, $idmatch[1]);

It says:
Undefined offset: 1 in /data/26/1/106/43/1921206/user/2092828/htdocs/admin/page.php on line 93

Line 93 is the third line in that snippet.

Reforced said

Thank you very much for all this information!

Marcel said

This was very helpful. Thank you

Mel said

Thank you so much! Lifesaver today when my host wreaked all my client websites by upgrading to 5.3 during the night. What a horrendous morning I’ve had. So thankful for the detail in your post.

Terijez said

Thank you!

mori said

I just want to thank you for this helpful article. solved my problem

Diana said

I tried this and my page is still not working. It return an error of:
PHP Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in /home/standup/public_html/templates/v5/browser.php on line 27

Here is a look at what I tried:

*******************************

// find operating system
if (preg_match(“/win/i”, $agent))
$bd['platform'] = “Windows”;
elseif (preg_match(“/mac/i”, $agent))
$bd['platform'] = “MacIntosh”;
elseif (preg_match(“/linux/i”, $agent))
$bd['platform'] = “Linux”;
elseif (preg_match(“/OS/2/i”, $agent)) (this is line 27)
$bd['platform'] = “OS/2″;
elseif (preg_match(“/BeOS/i”, $agent))
$bd['platform'] = “BeOS”;

*****************************************

Can anyone look at this code and show me what to do for my situation? Below is what I started with before making the preg_match.

class browser{

var $Name = “Unknown”;
var $Version = “Unknown”;
var $Platform = “Unknown”;
var $UserAgent = “Not reported”;
var $AOL = false;

function browser(){
$agent = $_SERVER['HTTP_USER_AGENT'];

// initialize properties
$bd['platform'] = “Unknown”;
$bd['browser'] = “Unknown”;
$bd['version'] = “Unknown”;
$this->UserAgent = $agent;

// find operating system
if (eregi(“win”, $agent))
$bd['platform'] = “Windows”;
elseif (eregi(“mac”, $agent))
$bd['platform'] = “MacIntosh”;
elseif (eregi(“linux”, $agent))
$bd['platform'] = “Linux”;
elseif (eregi(“OS/2″, $agent))
$bd['platform'] = “OS/2″;
elseif (eregi(“BeOS”, $agent))
$bd['platform'] = “BeOS”;

// test for Opera
if (eregi(“opera”,$agent)){
$val = stristr($agent, “opera”);
if (eregi(“/”, $val)){
$val = explode(“/”,$val);
$bd['browser'] = $val[0];
$val = explode(” “,$val[1]);
$bd['version'] = $val[0];
}else{
$val = explode(” “,stristr($val,”opera”));
$bd['browser'] = $val[0];
$bd['version'] = $val[1];
}

// test for WebTV
}elseif(eregi(“webtv”,$agent)){
$val = explode(“/”,stristr($agent,”webtv”));
$bd['browser'] = $val[0];
$bd['version'] = $val[1];

// test for MS Internet Explorer version 1
}elseif(eregi(“microsoft internet explorer”, $agent)){
$bd['browser'] = “MSIE”;
$bd['version'] = “1.0″;
$var = stristr($agent, “/”);
if (ereg(“308|425|426|474|0b1″, $var)){
$bd['version'] = “1.5″;
}

// test for NetPositive
}elseif(eregi(“NetPositive”, $agent)){
$val = explode(“/”,stristr($agent,”NetPositive”));
$bd['platform'] = “BeOS”;
$bd['browser'] = $val[0];
$bd['version'] = $val[1];

// test for MS Internet Explorer
}elseif(eregi(“msie”,$agent) && !eregi(“opera”,$agent)){
$val = explode(” “,stristr($agent,”msie”));
$bd['browser'] = $val[0];
$bd['version'] = $val[1];

// test for MS Pocket Internet Explorer
}elseif(eregi(“mspie”,$agent) || eregi(‘pocket’, $agent)){
$val = explode(” “,stristr($agent,”mspie”));
$bd['browser'] = “MSPIE”;
$bd['platform'] = “WindowsCE”;
if (eregi(“mspie”, $agent))
$bd['version'] = $val[1];
else {
$val = explode(“/”,$agent);
$bd['version'] = $val[1];
}

Funghie said

Hi there, Thanks for this – Total life saver. I have had to change hundreds of lines in an outdated CMS I use and it has all gone OK except I ran across one area that I cannot figure (or test). Wonder if someone can correct this for me:

elseif(eregi($ip, $clientip))

Thanks in advance. :-)

Funghie said

I used this:

elseif(preg_match(“/$ip, $clientip/”i))

Hopefully it is correct – The CMS still seems to work. :-)

Funghie said

BTW Diana,

I think your problem on line 27 is the delimiters. It should work by using a different delimiter:

// find operating system
if (preg_match(“#win#i”, $agent))
$bd['platform'] = “Windows”;
elseif (preg_match(“#mac#i”, $agent))
$bd['platform'] = “MacIntosh”;
elseif (preg_match(“#linux#i”, $agent))
$bd['platform'] = “Linux”;
elseif (preg_match(“#OS/2#i″, $agent))
$bd['platform'] = “OS/2″;
elseif (preg_match(“#BeOS#i”, $agent))
$bd['platform'] = “BeOS”;

And so on…

Plork said

preg_match sometimes makes things worse :(

you van also replace all eregi by mb_ereg

Shorty said

all the comments that ive seen here have work well, but im having trouble with displaying images.

i get the following error:

Deprecated: Function eregi_replace() is deprecated in /home/content/23/9272323/html/thumbnail.php on line 15

Deprecated: Function eregi_replace() is deprecated in /home/content/23/9272323/html/thumbnail.php on line 28

Deprecated: Function eregi_replace() is deprecated in /home/content/23/9272323/html/thumbnail.php on line 30

Ive looked at thumbnail.php and found the line numbers 15 – 28 – 30

line 30 – $pic = eregi_replace(‘ ‘,’%20′,$_GET['pic']);
line 28 – $pic = eregi_replace(‘ ‘,’%20′,$_GET['pic']);
line 30 – $pic_cached = eregi_replace($image->image_basedir,”,$pic_no_spaces);

anyone able to help me

thanks in advance
but cant figure out what to change

preg_match said

$check_url = str_replace(“\””, “”, $check_url);
if ((eregi(“]*script*\”?[^>]*>”, $check_url)) || (eregi(“]*object*\”?[^>]*>”, $check_url)) ||
(eregi(“]*iframe*\”?[^>]*>”, $check_url)) || (eregi(“]*applet*\”?[^>]*>”, $check_url)) ||
(eregi(“]*meta*\”?[^>]*>”, $check_url)) || (eregi(“]*style*\”?[^>]*>”, $check_url)) ||
(eregi(“]*form*\”?[^>]*>”, $check_url)) || (eregi(“\([^>]*\”?[^)]*\)”, $check_url)) ||
(eregi(“\””, $check_url))) {

becomes:

$check_url = str_replace(“\””, “”, $check_url);
if ((preg_match(“/]*script*\/i”?[^>]*>”, $check_url)) || (preg_match(“/]*object*\/i”?[^>]*>”, $check_url)) ||
(preg_match(“/]*iframe*\/i”?[^>]*>”, $check_url)) || (preg_match(“/]*applet*\/i”?[^>]*>”, $check_url)) ||
(preg_match(“/]*meta*\/i”?[^>]*>”, $check_url)) || (preg_match(“/]*style*\/i”?[^>]*>”, $check_url)) ||
(preg_match(“/]*form*\/i”?[^>]*>”, $check_url)) || (preg_match(“/\([^>]*\/i”?[^)]*\)”, $check_url)) ||
(preg_match(““/\”/i”, $check_url))) {

mister_tech said

Hi,
I have the following problem: Warning: preg_match(): Unknown modifier

Referencing the following code:
if($_POST["godate"]){
if(preg_match(“([0-9]{1,2})[\/-]+([0-9]{1,2})[\/-]+([0-9] {4})”,$_POST["godate"],$dater)){
$_SESSION["m"] = $dater[1];
$_SESSION["a"] = $dater[2];
$_SESSION["y"] = $dater[3];
$m = $dater[1];
$m = $dater[2];
$m = $dater[3];
}
}

Can someone help!

robert said

i tried to change it but after the changes nothing writes in in my email.xml file :( how else can i change it? Pls help…

if(trim($_POST['email']) == ”) {
$hasError = true;
} else if (!eregi(“^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$”, trim($_POST['email']))) {
$hasError = true;
} else {
$email = trim($_POST['email']);

peter said

amazing, thanks!

teemoz said

Hi
i am new in php can someone plz help with this code how can i change it
$eregi = eregi_replace($regex, ”, $email);

Sagar said

great help saved my day!!!!!!!

Newbi said

Thanks a lot was stuck with these warnings for eternity :) was of great help.

Nova said

Anyone help me change to pre_match()?

Toufiq said

Please Help me anybody
Deprecated: Function ereg() is deprecated in /home/amartune/public_html/service/modules/mod_s5_horizontal_accordion/mod_s5_horizontal_accordion.php on line 69

Deprecated: Function ereg() is deprecated in /home/amartune/public_html/service/modules/mod_s5_horizontal_accordion/mod_s5_horizontal_accordion.php on line 72

Jeff said

What about this one:

if (ereg($ip,$line)) { $badbot++; }

repair pc said

Hello just wanted to give you a quick heads up.
The text in your article seem to be running off the screen in Chrome.
I’m not sure if this is a formatting issue or something to do with internet browser compatibility but I thought I’d post to let you know. The design look great though! Hope you get the issue fixed soon. Kudos

coop said

thanks. it works!

Shivam Rastogi said

Thanks for above solution. Keep posting and helping people.

Roy said

Thanks! Worked

Hello. Ifroom Polish said


if($option['activeon'])
foreach($option['activeon'] as $activeon){
if(eregi($action, $activeon)){
$option['active']=true;
}}

http://i49.tinypic.com/24m8io8.jpg

HELP

mike said

how would i rewrite this?
if((eregi($suspect, $lowmsg)) || (eregi($suspect, strtolower($_POST['name']))) || (eregi($suspect, strtolower($_POST['email']))))

Roy said

Thnx, works like a charm

saroj said

if((eregi($suspect, $lowmsg)) || (eregi($suspect, strtolower($_POST['name']))) || (eregi($suspect, strtolower($_POST['email']))))

Just Replace eregi to preg_match your problem will solve.

elena said

If /i doesn´t work you can try to put # before and #i in the end, for an example:

eregi( ‘Itemid=’, $row->link ) //change to this:
preg_match( ‘#Itemid=#i’, $row->link )

Hope it helps someone!!

Graham said

Thankyou…

really though… It’s not often a first google search turns out to be the major fix you were looking for.

Cheers!

jojo said

how to change
//if (!eregi(“^(http|https)://”, $url))
if (!eregi(“^(http|https|ftp|telnet|news|mms)://”, $url))
$url = “http://” . $url;

Please help me.

Many thanks,

Greg said

Thank you for this fix. I was going nuts for 2 days and customer support was telling me what I have its not supported and I have to get a new plan. I was trying to figure this out on my own for 2 days… and I came onto this site and fixed it in 2 minutes.
Thank you again!!!

Andree said

how would i rewrite this?
if (!isset($HTTP_SERVER_VARS['PHP_SELF']) && eregi(“cc_controller.php”, $HTTP_SERVER_VARS['PHP_SELF']) || eregi(“cc_controller.php”, $_SERVER['PHP_SELF']))

and this one.

if (!ereg(“logout|login|requestPass”, $_GET['_g']))

i have replace with preg_match and dont work

tony said

Alguien me puede ayudar?, como puedo corregir lo siguiente.

Deprecated: Function eregi() is deprecated in /home/floresym/public_html/includes/classes/language.php on line 87

esto es lo que me pone al entrar a mi web

, y si entro en esa carpeta pone:

if (eregi(‘^(‘ . $value . ‘)(;q=[0-9]\\.[0-9])?$’, $this->browser_languages[$i]) && isset($this->catalog_languages[$key])) {

como tendría que ponerlo? gracias de antemano

Sonny said

that was a pretty quick fix, thanks

CYMER said

how do i fix this?

Deprecated:Function session_is_registered()is deprecated in C:\xampp\htdocs\cymer\login.php on line 57

Deprecated:Function session_is_registered()is deprecated in C:\xampp\htdocs\cymer\index.php on line 36

Deprecated:Function session_is_registered()is deprecated in C:\xampp\htdocs\cymer\index.php on line 38

Deprecated:Function session_is_registered()is deprecated in C:\xampp\htdocs\cymer\index.php on line 49

Deprecated:Function session_is_registered()is deprecated in C:\xampp\htdocs\cymer\index.php on line 51

Deprecated:Function session_is_registered()is deprecated in C:\xampp\htdocs\cymer\index.php on line 66

Deprecated:Function session_is_registered()is deprecated in C:\xampp\htdocs\cymer\index.php on line 68

please help me…thanks!

Quadry said

Deprecated: Function ereg() is deprecated in /home/rccgopen/public_html/ohcc/templates/touch_of_soul/index.php on line 64

Deprecated: Function ereg() is deprecated in /home/rccgopen/public_html/ohcc/templates/touch_of_soul/index.php on line 68

Deprecated: Function ereg() is deprecated in /home/rccgopen/public_html/ohcc/templates/touch_of_soul/index.php on line 72

Your thoughts?

About Guillermo Rauch:

CTO and co-founder of LearnBoost / Cloudup (acquired by Automattic in 2013). Argentine living in SF.