Search code examples
phppreg-replacephp-5.5preg-replace-callback

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback in Echelon B3


    function removeColorCode($text) {
      return preg_replace('/\\^([0-9])/ie', '', $text);
    }

The above code gives a deprecation warning on Echelon B3 i think after upgrading to PHP 5.5.29 by our host provider


How can I replace the code properly with preg_replace_callback()?


Solution

  • In this specific case, just remove the /e it does nothing here.
    You can also remove the /i So your code becomes:

    function removeColorCode($text) {
      return preg_replace('/\^[0-9]/', '', $text);
    }