In the latest project, after updating PHP, we found that the e modifier of preg_replace () has been discarded since version 5.5.0. I don't know how to rewrite {code...}. Could you advise me on the latest project? After updating PHP, I found that preg_replace () started in version 5.5.0.
/eThe modifier has been discarded. Then I don't know how to rewrite it.
$source_content = preg_replace($search.'e', "'" . $this->_quote_replace($this->left_delimiter) . 'php' . "' . str_repeat(\"\n\", substr_count('\\0', \"\n\")) .'" . $this->_quote_replace($this->right_delimiter) . "'" , $source_content);
Please advise
Reply content:
In the latest project, after updating PHP, we found that preg_replace () started in version 5.5.0./eThe modifier has been discarded. Then I don't know how to rewrite it.
$source_content = preg_replace($search.'e', "'" . $this->_quote_replace($this->left_delimiter) . 'php' . "' . str_repeat(\"\n\", substr_count('\\0', \"\n\")) .'" . $this->_quote_replace($this->right_delimiter) . "'" , $source_content);
Please advise
Yespreg_replace()Of/eThe mode has been deprecated, notpreg_replace()Abandoned !! Please do not speak in an abstract way !! I was so scared at the beginning that I thought PHP was so casual.
preg_replace_callback()Isn't it very easy? I just replaced it with a function.evalExecution string. But I honestly don't know what your replacement execution function is doing. It seems that you want to rewrite the line feed based on the number of line breaks ?? Write a reference for you:
$source_content = preg_replace_callback($search, function($matches) { return str_repeat("\n", substr_count($matches[0], "\n");}, $cource_content);
Function$matchesThe parameter is yours.$searchIf you still don't understand the matching result, check the manual. The manual has been fully written.
Here is the answer officially provided by smarty:
$ Source_content = preg_replace_callback ($ search, create_function ('$ matches', "return '"
. $ This-> _ quote_replace ($ this-> left_delimiter). 'php'
. "'. Str_repeat (\" \ n \ ", substr_count (' \ $ matches [1] ', \" \ n \")).'"
. $ This-> _ quote_replace ($ this-> right_delimiter)
. "';"), $ Source_content );