0

I have a code like this. I think it just about PHP5/PHP7 compatiable problem

 function EncodeQ ($str, $position = 'text') {
    $encoded = preg_replace("[\r\n]", '', $str);
    switch (strtolower($position)) {
      case 'phrase':
        $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
        break;
      case 'comment':
        $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
      case 'text':
      default:
        $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
              "'='.sprintf('%02X', ord('\\1'))", $encoded);
        break;
    }

    $encoded = str_replace(' ', '_', $encoded);

    return $encoded;
  }

Please help me to fix the code, the error is following

preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead

chris85
  • 23,846
  • 7
  • 34
  • 51
  • I think this thread answers to the question: http://stackoverflow.com/questions/15454220/replace-preg-replace-e-modifier-with-preg-replace-callback – Jannunen Mar 10 '16 at 21:11
  • There another question, but I cannot get from the above-mentioned post $text = preg_replace("#\[tex\](.*?)\[/tex\]#sie","'\'\\1\''", $text); How should I do? – user2096016 Mar 10 '16 at 22:21

0 Answers0