Codecolorer - preg_replace_callback()

vaclavambroz

I use Wordpress plugin Codecolorer (https://wordpress.org/plugins/codecolorer/) and on PHP 7 I have this problem:

  /** Search content for code tags and replace it */
  function BeforeHighlightCodeBlock($content) {
    $content = preg_replace('#(\s*)\[cc([^\s\]_]*(?:_[^\s\]]*)?)([^\]]*)\](.*?)\[/cc\2\](\s*)#sie', '$this->PerformHighlightCodeBlock(\'\\4\', \'\\3\', $content, \'\\2\', \'\\1\', \'\\5\');', $content);
    $content = preg_replace('#(\s*)\<code(.*?)\>(.*?)\</code\>(\s*)#sie', '$this->PerformHighlightCodeBlock(\'\\3\', \'\\2\', $content, \'\', \'\\1\', \'\\4\');', $content);

    return $content;
  }

Gives me:

[Thu Dec 10 17:02:36.552179 2015] [:error] [pid 19451] [client 127.0.0.1:48652] PHP Warning:  preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /var/www/html/xxx/wp-content/plugins/codecolorer/codecolorer-core.php on line 49, referer: http://xxx/
[Thu Dec 10 17:02:36.552202 2015] [:error] [pid 19451] [client 127.0.0.1:48652] PHP Warning:  preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /var/www/html/xxx/wp-content/plugins/codecolorer/codecolorer-core.php on line 50, referer: http://xxx/

So I tried to change it to:

/** Search content for code tags and replace it */
  function BeforeHighlightCodeBlock($content) {
    $content = preg_replace_callback('#(\s*)\[cc([^\s\]_]*(?:_[^\s\]]*)?)([^\]]*)\](.*?)\[/cc\2\](\s*)#si', '$this->PerformHighlightCodeBlock(\'\\4\', \'\\3\', $content, \'\\2\', \'\\1\', \'\\5\');', $content);
    $content = preg_replace_callback('#(\s*)\<code(.*?)\>(.*?)\</code\>(\s*)#si', '$this->PerformHighlightCodeBlock(\'\\3\', \'\\2\', $content, \'\', \'\\1\', \'\\4\');', $content);

    return $content;
  }

But now I get this error:

[Thu Dec 10 17:05:52.331876 2015] [:error] [pid 19451] [client 127.0.0.1:48714] PHP Warning:  preg_replace_callback(): Requires argument 2, '$this-&gt;PerformHighlightCodeBlock('\\4', '\\3', $content, '\\2', '\\1', '\\5');', to be a valid callback in /var/www/html/xxx/wp-content/plugins/codecolorer/codecolorer-core.php on line 49
[Thu Dec 10 17:05:52.331910 2015] [:error] [pid 19451] [client 127.0.0.1:48714] PHP Warning:  preg_replace_callback(): Requires argument 2, '$this-&gt;PerformHighlightCodeBlock('\\3', '\\2', $content, '', '\\1', '\\4');', to be a valid callback in /var/www/html/xxx/wp-content/plugins/codecolorer/codecolorer-core.php on line 50

Please can you help me to fix this? Thank you!

Alexander Mikhalchenko

You should actually pass either a function name or a callable object as the second argument.

preg_replace_callback('#(\s*)\[cc([^\s\]_]*(?:_[^\s\]]*)?)([^\]]*)\](.*?)\[/cc\2\](\s*)#si', function($matches){
    // Do something
    return $string; // return some string
}, $content);

You can read more about that in the docs.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Using preg_replace_callback

From Dev

Preg_replace and Preg_replace_callback

From Dev

Replace 'e' modifier with preg_replace_callback

From Dev

Replace deprecated preg_replace /e with preg_replace_callback

From Dev

Replace preg_replace() to preg_replace_callback()

From Dev

PHP preg_replace_callback ignore id

From Dev

preg_replace_callback: Unknown modifier '!'

From Dev

Replacing /e modifier with preg_replace_callback

From Dev

preg_replace_callback not working in php

From Dev

preg_replace_callback returns duplicate values

From Dev

Php, Regex preg_replace_callback

From Dev

Using preg_replace_callback with shortcodes

From Dev

sort properties with preg_replace_callback

From Dev

Preg_replace_callback storing in array

From Dev

Php, Regex preg_replace_callback

From Dev

Replacing /e modifier with preg_replace_callback

From Dev

preg_replace_callback with Spoilers into Spoilers

From Dev

How to use preg_replace_callback

From Dev

preg_replace_callback - compilation failed

From Dev

Get opposite match with preg_replace_callback

From Dev

PHP REGEX preg_replace_callback not matching

From Dev

preg_replace to preg_replace_callback with an array as replacement

From Dev

convert preg_replace to preg_replace_callback modifier error

From Dev

FROM preg_replace TO preg_replace_callback

From Dev

php converting preg_replace to preg_replace_callback

From Dev

preg_replace to preg_replace_callback with an array as replacement

From Dev

Convert preg_replace to preg_replace_callback

From Dev

FROM preg_replace TO preg_replace_callback

From Dev

preg_replace_callback(): Requires argument 2, 'Array', to be a valid callback

Related Related

HotTag

Archive