Hi all I've got a question having a obsolete/deprecated function.

I have to change ereg to preg_match

the code using the function is: http://pastebin.com/jMBkJSEr

I tired to alter ereg to preg_match however it does not work just by altering the title from the function.

You have 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);
}

You will find also a number of other ereg_replace calls which you may 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 need to change those 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 exactly what you would like

EDIT :

There's just 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);

We do hope you have it.

EDIT:

Even the split is depreciated . You need to change:

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

to

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

Hope this stuff can help you