phpregexpreg-replaceeregiereg

Need help in rephraseing two lines of code because.eregi_replace is depricated


So I purchased a script package which is using eregi_replace and I do not know how to re-write the code to play with preg_replace()

The error is: Deprecated: Function eregi_replace() is deprecated in /home2/leemonster/scripttk.com/helpDesk/inc/header.php on line 19

The code is:

if (isset($theme_dir)) 
    $temp = preg_replace('/( href=")([^>]*?eticket\.css")/is', '$1' . $theme_dir . '$2', $temp);

if (isset($page)) 
    $temp = str_replace('admin.php', $page, $temp);
if (isset($page)) 
    $temp = str_replace('index.php', $page, $temp);

$header = eregi_replace($bodytag . '.*', '', $temp);
$footer = eregi_replace('.*' . $bodytag, '', $temp);

Solution

  • $header = preg_replace('/' . $bodytag . '.*/i', '', $temp);
    $footer = preg_replace('/.*' . $bodytag . '/i', '', $temp);
    

    I've added a delimiter, / in this case (can be other characters too), that needs to surround all preg regular expressions, as well as the i flag that makes the match case-insensitive. Just make sure that $bodytag doesn't contain said delimiters unescaped.

    I'd recommend you read up on how the preg suite works, here's a good place to start.