0

Hi all I have a question with a obsolete/deprecated function.

I need to change ereg to preg_match

the code with the function is this: http://pastebin.com/jMBkJSEr

I tired to change ereg to preg_match but it doesn't work by just changing the name of the function.

hakre
  • 193,403
  • 52
  • 435
  • 836
  • In which funtion in oscommerce tep_sanitize_string ?? – Sabari Jan 30 '12 at 16:07
  • possible duplicate of [Converting ereg expressions to preg](http://stackoverflow.com/questions/6270004/converting-ereg-expressions-to-preg) – hakre Jan 30 '12 at 16:09
  • yes is oscommerce the problem is on advanced_search_result.php on line 306 – Felipe Ignacio Victoriano Vict Jan 30 '12 at 16:09
  • You should probably get into contact with the OSCommerce community and solve the problem collectively. I guess you're not the only one with the problem and it might have been solved already. – hakre Jan 30 '12 at 16:15

3 Answers3

2

in addition to those outlined above, there is also eregi that must be updated, which is just a case insensitive version of ereg. So, replace it with the preg_match and the 'i' switch to make it case insensitive.

Change eregi

eregi('RegExp', $x)

to preg_match (note the "i" after the second /)

preg_match('/RegExp/i', $x)

krnlpanic
  • 43
  • 7
1

You need to change :

function tep_sanitize_string($string) {
        $string = ereg_replace(' +', ' ', trim($string));

        return preg_replace("/[<>]/", '_', $string);
}

to

function tep_sanitize_string($string) {
        $string = preg_replace('{ +}', ' ', trim($string));

        return preg_replace("/[<>]/", '_', $string);
}

There are also many other ereg_replace calls that you might find:

ereg_replace('2037' . '$', $year, date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, 2037)));
ereg_replace('"', ' ', $pieces[$k]);
ereg_replace('(' . implode('|', $from) . ')', $to, $string);
ereg_replace('[^0-9]', '', $number);
ereg_replace('-language', '-' . $languages[$j]['directory'], $cached_file);
ereg_replace('(' . implode('|', $from) . ')', $to, $string);
ereg_replace("\r","",$which_text);
ereg_replace('-language', '-' . $language, $cache_blocks[$i]['file']);
ereg_replace(",\n$", '', $schema);
ereg_replace("\n#", "\n".'\#', $row);
ereg_replace(', $', '', $schema);

You should change these to

preg_replace('{2037\z}', $year, date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, 2037)));
str_replace('"', ' ', $pieces[$k]);
preg_replace('{(' . implode('|', $from) . ')}', $to, $string);
preg_replace('{\D}', '', $number);
str_replace('-language', '-' . $languages[$j]['directory'], $cached_file);
str_replace("\r","",$which_text);
str_replace('-language', '-' . $language, $cache_blocks[$i]['file']);
preg_replace("{,\n\z}", '', $schema);
preg_replace("{\n#}", "\n".'\#', $row);
preg_replace('{, \z}', '', $schema);

Hope this is what you want

EDIT :

There is only one change:

ereg('RegExp', $x $y);

to

preg_match('/RegExp/', $x $y);

Same for “ereg_replace”

ereg_replace('RegExp', $x, $y);

to

preg_replace('/RegExp/', $x, $y);

Hope you get it.

EDIT:

Also the split is depreciated . You should change:

$pieces = split('[[:space:]]+', $search_str);

to

$pieces = preg_split("/[\s,]+/", $search_str);

Hope these things helps you

Sabari
  • 6,205
  • 1
  • 27
  • 36
0

The new version of oscommerce has changed eregi to preg_match

eregi('eregi data here ', $x)
preg_match('/here your eregi data/', $x)
Tomas Pastircak
  • 2,867
  • 16
  • 28
GatuTeck
  • 1
  • 2