phpereg-replace

Replace ereg_match with preg_match


Dear Sir/m'am How can i replace ther deprecated ereg_replace with preg_replace or str_replace and still have the same functionality as in the code below?

return ereg_replace("^(.*)%%number%%(.*)$","\\1$i\\2",$number);

///this doesnt work

return preg_replace("^(.*)%%number%%(.*)$","\\1$i\\2",$number);

Anyone smarter have a clue?


Solution

  • Try this:

    return ereg_replace("^(.*)%%number%%(.*)$","\\1$i\\2",$number);
    

    becomes

    return preg_replace("/^(.*)%%number%%(.*)$/","\\1$i\\2",$number);
    

    Note the / around the regex.