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
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.'&w='.
tep_output_string($width).'&h='.tep_output_string($height).'&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);
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.
ASKER
Yes, SEO is enabled.
ASKER
I have WAMP installed. Complete path is
C:/wamp/www/languageimages /images
C:/wamp/www/languageimages
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.'&w='.
tep_output_string($width).'&h='.tep_output_string($height).'&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);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It worked! I cannot tell you how long I have been struggling with this. Thank you so much.
Julie
Julie
ASKER
Excellent. Easy to understand and a life saver.
No worries :), glad to have helped. Good luck on your future PHP scripting!
please provide images/ complete path like d:/......or /var/.....
so that we can trap if there is any issue.
SEO_ENABLED ??