Link to home
Start Free TrialLog in
Avatar of jullialynch
jullialynch

asked on

Need help fixing deprecated eregi errors

I am updating my site to comply with php 5.3.0. I am just learning php.
How do I fix eregi errors that involve "images/"? I am not sure what delimiters to use or where to place them so that the images are still available.
Please look at the attached snippet of code and advise.
Thank you,
Julie
//Return the normal html if not SEO
	if (SEO_ENABLED != 'true' || !eregi("images/", $src)) {  //this only works on images in the images/ directory
				$image = '<img src="imagemagic.php?img='.$src.'&amp;w='.
				tep_output_string($width).'&h='.tep_output_string($height).'&amp;page='.$page.'"';
			} else {
				
				$src = str_replace("images/", "", $src);  //implied
				//return case sensitive extension
				if (eregi(".jpg", $src)) {
					$type=substr($src, stripos($src,".jpg"), 4);
				} elseif (eregi(".jpeg", $src)) {
					$type=substr($src, stripos($src,".jpeg"), 5);		
				} elseif (eregi(".gif", $src)) {
					$type=substr($src, stripos($src,".gif"), 4);		
				} elseif (eregi(".png", $src)) {
					$type=substr($src, stripos($src,".png"), 4);

Open in new window

Avatar of Insoftservice inso
Insoftservice inso
Flag of India image

hi,

please provide images/ complete path like d:/......or /var/.....

so that we can trap if there is any issue.
SEO_ENABLED ??
Avatar of SleepinDevil
SleepinDevil

The new function set instead of "eregi" is "preg_match" and you should be able to implement that easy by just replacing all the "eregi" (http://php.net/manual/en/function.eregi.php) with "preg_match" (http://www.php.net/manual/en/function.preg-match.php) however your code doesnt do any complete REGEX tests. So you might as well use just strpos() after this comment ill post again with your code changed over to use "strpos" (http://php.net/manual/en/function.strpos.php) instead.
Avatar of jullialynch

ASKER

Yes, SEO is enabled.
I have WAMP installed. Complete path is
C:/wamp/www/languageimages/images
About the errors you get. This is because "/" is a special symbol in REGEX and should be escaped. To escape special symbols put a \ infront of it. So instead of "images/" do "images\/"
//Return the normal html if not SEO 
        if (SEO_ENABLED != 'true' || !strpos($src, "images/")) {  //this only works on images in the images/ directory 
                                $image = '<img src="imagemagic.php?img='.$src.'&amp;w='. 
                                tep_output_string($width).'&h='.tep_output_string($height).'&amp;page='.$page.'"'; 
                        } else { 
                                 
                                $src = str_replace("images/", "", $src);  //implied 
                                //return case sensitive extension 
                                if (strpos($src, ".jpg")) { 
                                        $type=substr($src, stripos($src,".jpg"), 4); 
                                } elseif (strpos($src, ".jpeg")) { 
                                        $type=substr($src, stripos($src,".jpeg"), 5);            
                                } elseif (strpos($src, ".gif")) { 
                                        $type=substr($src, stripos($src,".gif"), 4);             
                                } elseif (strpos($src, ".png")) { 
                                        $type=substr($src, stripos($src,".png"), 4);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of SleepinDevil
SleepinDevil

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It worked! I cannot tell you how long I have been struggling with this. Thank you so much.
Julie
Excellent. Easy to understand and a life saver.
No worries :), glad to have helped. Good luck on your future PHP scripting!