Reputation: 1
I'm trying to update the code for some very old plugins for a very old blog. I've fixed almost everything except this.
I get an error message that I must replace preg_replace with preg_replace_callback.
This is the code:
$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);
If I simply substitute preg_replace_callback for the preg_replace I get this error:
preg_replace_callback(): Requires argument 2, ''{{php' . str_repeat(" ", substr_count('\0', " ")) .'}}'', to be a valid callback in
I'm neither a perl nor a php person. Any help would be much appreciated!
Upvotes: 0
Views: 114
Reputation:
Upgrading your smarty library to the latest smarty2 would solve your problem fix was there over 5 years now.
But This might help you :
$source_content = preg_replace_callback($search . 'e',
function ($matches) {
return "'"
. $this->_quote_replace($this->left_delimiter) . 'php'
. "' . str_repeat(\"\n\", substr_count('$matches[0]', \"\n\")) .'"
. $this->_quote_replace($this->right_delimiter) . "'";
},
$source_content
);
Here is the explanition and more examples : https://www.php.net/manual/en/function.preg-replace-callback.php
Upvotes: 1