Recent projects, after updating PHP found Preg_replace () from version 5.5.0
/e
Modifier has been deprecated. And 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);
Ask the Great God for advice
Reply content:
Recent projects, after updating PHP, found that the preg_replace () modifier has been deprecated in the 5.5.0 version. /e
And 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);
Ask the Great God for advice
preg_replace()
The /e
pattern was abandoned, not abandoned, preg_replace()
okay! Please do not generalize the words!! I was scared to pee at first, and I thought PHP was so casual.
preg_replace_callback()
is not very simple, is to replace with the function with the eval
execution string ah. But honestly, I don't know how to do that. What exactly do you want to do with the replacement execution function, as if you want to re-write the line break according to 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);
The parameter of the function $matches
is the result of your $search
match, if you still do not understand or look at the manual, the manual has been written in full.
Here is the answer given by the official 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);