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);
160 Comments
I’ve found that almost anything can be used as a delimiter with preg_match. I personally use ~ as I use it the least.
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.
Pingback: Migración a PHp 5.3: primeras experiencias
Pingback: Brady J. Frey + Eregi deprecation for PHP 5.3 in CubeCart
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:)
GREAT!GREAT!GREAT!
Thanks worked well
Pingback: PHP Deprecated error – Fix `ereg is deprecated` errors in PHP 5.3 | Buzz / Press
Thanks!
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!
Pingback: Aleksandar Gvozden Info » Fix `ereg is deprecated` errors in PHP 5.3
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!
Clear Fix For NeverEnding Programmings !
What’s happen with split function deprecated too ?
veru simple : split() change for explode() in same conditions
Hi thank u very much, it helped me a lot………
Thanks!! Really!! I Luv U!!!
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.
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
Use explode().
thx!
Thank you!
can’t resolve this one
$msg =ereg_replace(“(http|https|ftp|gopher|news)://([$ACCEPT_CHARS]+)”, “\\1://\\2” , $msg);
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??!!
doesen’t browser informs you about error when you test your project? it should say where error is. file and line no.
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.
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
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'] = “”;
}
Pingback: La Thinking Motion. - [php5.3] Function ereg() is deprecated 対応方法 [error]
Hi.. ereg() with preg_match() is working well
Great site. helps me a lot.
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
A very usefull post, it saved my day. Thnx
so, what would i edit to make this work properly:
elseif(!eregi(“http://”,$uri) && !eregi(“https://”,$uri))
anybody? im really stuck! thanks in advance
elseif(!preg_match(“#http://#i”,$uri) && !preg_match(“#https://#i”,$uri))
Thanks, ymmd :)
Thanks for this, fixed my problem after we upgraded PHP to 5.3 and our WordPress theme choked. Much appreciated!
Thaaaaaaaaaaanks its working !
Thanks for this post it’s just exactly what i was looking for
Hvala na postu!
Thank You for this post!
Very elegant solution!
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!
Pingback: Achecker, validare le vostre pagine web « Software Libero e non solo
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
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.
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
Try this
if (!preg_match(‘#^’ . DIR_FS_DOCUMENT_ROOT.’#i’, $current_path)) $current_path = DIR_FS_DOCUMENT_ROOT;
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?
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'])
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.
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.”
Thanks for this page. It is really clear.
Thanx alot its very helpful
Nice topic . Thank you for posting it !
Tui ki bojis nice topic ar ?
Deprecated: Function eregi() is deprecated in C:\wamp\www\memories-on-gold\includes\classes\language.php on line 87 any one help me.
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
Hi… that was really a helpfull post.. Thnx… :)
couldnt match with your solution
any help?
if (!eregi(“(^\.\.?)”, $file)) {
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.
sasasa
Thanks, very useful information.! i have some issue with deprecated syntax in php and need to replace it one by one. fiuh..
hi, thanks.usefull info
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.
Pingback: Blog de Perberos » Como arreglar el ereg is deprecated en php 5.3
Thankss alot that help fully
coll. nice dara man
Pingback: PHP: ereg y eregi obsoletos (deprecated) en PHP 5.3.x « Outbook
great thanks for this tricks
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
Solved i had to insert single quotes:
if (preg_match(‘/$Match/i’,$_SERVER['HTTP_USER_AGENT']))
Damn it doesn’t work I didn’t notice it because the error wasn’t displayed anymore but it returned wrong result
If someone is having the same problem the solution weren’t single quotes but DOUBLE “”
very complex stuff but thank you for trying to make sense out of this error
sasasa
Thank you very much, just what i needed.
that’s excellent thanks a lot!!!
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.
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
As clear as water :)
Thanks
Excellent! This help me a lot.
how that code work?
i try this code but no effect,,
anybody could help me?
eregi (“@.()+_*^%$#.[;]“, $branchname)
should i declare them one by one?
Try this:
preg_match(‘/@.()+_*^%$#.[;]/i’, ‘your_second_arument’, $branchname)
thanks for information, great post!
Cheers, that makes sense!
thanks! very useful
hi,
How to change ereg($startreg['format'], $date, $regs);
preg_match(‘/$startreg['format']/’, $date, $regs); is not working
maybe try to this
preg_match(‘/’.$startreg['format'].’/', $date, $regs);
or
$text = ‘/’.$startreg['format'].’/';
preg_match($text, $date, $regs);
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);
Thanx a lot!
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;
}
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
Whatever, it helps me!
wow so helpful
thanks
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
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
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))
Merci Beaucoup
EXCELLENT !!!! Simple and usefull… just what i needed… THX
Thank you!
jhhhj
How can i fix this:
if(preg_match(‘.+.[jJ][pP][eE]?[gG]$’, $arquivo)
if (preg_match(‘/.jpe?g$/i’, $arquivo)
Can I Know How to Fix This
if(eregi(‘No file(s) found for’, $result)) {
good job! very helpfull!!
Thank you very much for this useful information.
Which file do I make the changes in? I don’t see these lines in the existing timthumb.php file?
Thanks
Bryan
Hi, please How I change this function to new convert. eregi(‘.([^.]*$)’, $this->file_src_name, $extension);
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
cut your co.ck
Plz solve this i hv trouble in sloving this problem
Date :
Time :
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…
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?
Exactly what I was looking for. It helped me a lot. Thank you!!!
Loved you post.. you are saving lives.
Solved: explore …. Thks
How do I fix this:
!eregi(basename($_SERVER['PHP_SELF']), $fileName) && ereg(‘^[^./][^/]*$’, $fileName))
if ( eregi( ‘index.php?’, $row->link ) ) {
if ( !eregi( ‘Itemid=’, $row->link ) ) {
$row->link .= ‘&Itemid=’. $row->id;
}
How do I fix this:
if ( eregi( ‘index.php?’, $row->link ) ) {
if ( !eregi( ‘Itemid=’, $row->link ) ) {
$row->link .= ‘&Itemid=’. $row->id;
}
Thanks this was a useful guide.
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.
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”);
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??
Mate thanks a lot !
You just saved hours of hard working for me !
Thanks a lot Mate!!
you saved me today!!
Thanks.. :-)
you saved me!
another important thing is to replace \\1 with \${1} (I’ve found that out the hard way) :D
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!
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
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
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
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 .
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);
thanks…it works…awesome…
it’s working….
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.
Thank you very much for all this information!
This was very helpful. Thank you
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.
Thank you!
I just want to thank you for this helpful article. solved my problem
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];
}
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. :-)
I used this:
elseif(preg_match(“/$ip, $clientip/”i))
Hopefully it is correct – The CMS still seems to work. :-)
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…
preg_match sometimes makes things worse :(
you van also replace all eregi by mb_ereg
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
$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))) {
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!
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']);
amazing, thanks!