-1

I'm fixing an old script, that is thowing that warning (PHP Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead) in this line:

'.preg_replace("|\[session id=\"(.*)\"\](.*)\[/session\]|e", "\$_SESSION['wpcc_\\1']['\\2']", stripslashes(nl2br($wpcc_cache['text']))).'

EDIT: That is surronded by some <div> :

<div class="wpcc_fields wpcc_text wpcc_text_'.$row->wpcc_field.'"> '.preg_replace("|\[session id=\"(.*)\"\](.*)\[/session\]|e", "\$_SESSION['wpcc_\\1']['\\2']", stripslashes(nl2br($wpcc_cache['text']))).' </div>

EDIT END

I'm reading about how preg_replace_callback works, what did the e modifier and so on, but... can I just remove the e? I don't see why this preg_replace should have a callback, it has no function as replacement, isn't it? I'm also trying to figure what is inside $wpcc_cache['text'] , but haven't found yet

Jan Schultke
  • 17,446
  • 6
  • 47
  • 96
darthcharmander
  • 129
  • 1
  • 7
  • When `e` is set, the replacement string is evaluated as PHP code. So `stripslashes(nl2br($wpcc_cache['text'])))` _can_ contain some PHP code which would be evaluated. Just removing `e` would not evaluate the code and obviously lead to a different outcome. – deceze Aug 04 '23 at 12:15
  • but `stripslashes(nl2br($wpcc_cache['text']))` is not the replacement, is it? The replacement is the second parameter: `"\$_SESSION['wpcc_\\1']['\\2']"` , isn't it? I mean, `stripslashes(nl2br($wpcc_cache['text']))` is the subject, tha, by the way, is inside a `
    `: `
    '.preg_replace("|\[session id=\"(.*)\"\](.*)\[/session\]|e", "\$_SESSION['wpcc_\\1']['\\2']",stripslashes(nl2br($wpcc_cache['text']))).'
    ` I don't think ther is any code there... but I may be wrong, of course
    – darthcharmander Aug 04 '23 at 14:01
  • 1
    My bad, it’s `"\$_SESSION['wpcc_\\1']['\\2']"` that will be evaluated as code after `\1` and `\2` have been replaced by the regex. In other words, this does a value lookup in `$_SESSION` using values from the regex match as keys. You can certainly replace that with a callback instead. – deceze Aug 04 '23 at 14:12

0 Answers0