0

how Replace thes code from preg_replace() to preg_replace_callback() ?

$search_array   =   array();
$replace_array  =   array();

$search_array[]     =   '~\{\$([^[<].*?)\[\'([^[<].*?)\'\]\[\'([^[<].*?)\'\]\}~';
$replace_array[]    =   '<?php echo $DHGS->_CONF[\'template\'][\'\\1\'][\'\\2\'][\'\\3\']; ?>';

$search_array[]     =   '~\{\$([^[<].*?)\[([^[<].*?)\]\[([^[<].*?)\]\}~';
$replace_array[]    =   '<?php echo $DHGS->_CONF[\'template\'][\'\\1\'][\'\\2\'][\'\\3\']; ?>';

$search_array[]     =   '~\{\$([^[<].*?)\[\'([^[<].*?)\'\]\}~';
$replace_array[]    =   '<?php echo $DHGS->_CONF[\'template\'][\'\\1\'][\'\\2\']; ?>';

$search_array[]     =   '~\{\$([^[<].*?)\[([^[<].*?)\]\}~';
$replace_array[]    =   '<?php echo $DHGS->_CONF[\'template\'][\'\\1\'][\'\\2\']; ?>';

$search_array[]     =   '~\{\$([^[<].*?)\}~';
$replace_array[]    =   '<?php echo $DHGS->_CONF[\'template\'][\'\\1\']; ?>';

$search_array[]     =   '~\{template}([^[<].*?){/template}~';
$replace_array[]    =   '<?php $this->display(\'\\1\'); ?>';

$search_array[]     =   '~\{include}([^[<].*?){/include}~';
$replace_array[]    =   '<?php include(\\1); ?>';

$search_array[]     =   '~\{info_row}([^[<].*?){/info_row}~';
$replace_array[]    =   '<?php $this->info_row(\'\\1\'); ?>';

$search_array[]     =   '~\{get_hook}([^[<].*?){/get_hook}~';
$replace_array[]    =   '<?php $this->get_hooks_template(\'\\1\'); ?>';

//////////
$string = preg_replace($search_array,$replace_array,$string);

The above code gives deprecated warning.

How do Convert from preg_replace to preg_replace_callback ! I tried converting but it was a complicated process ..

  • what is the deprecation warnings that you get? I had tried your code in php7.3 and did not get any warnings – hassan Oct 28 '18 at 09:05
  • does not work correctly in PHP Version 7.2.9 php error preg_replace() the /e modifier is deprecated use preg_replace_callback instead – user10568573 Oct 28 '18 at 14:15
  • I do not see any `/e` modifiers in your posted code – hassan Oct 28 '18 at 14:30
  • Possible duplicate of [Replace preg\_replace() e modifier with preg\_replace\_callback](https://stackoverflow.com/questions/15454220/replace-preg-replace-e-modifier-with-preg-replace-callback) – hassan Oct 28 '18 at 14:31
  • Forget the warning It is not as important This code does not work well by preg_replace Can you change it to run on preg_replace_callback ? – user10568573 Oct 28 '18 at 14:37

0 Answers0