1

I am modifying one of our Joomla template and I am getting this warning.

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/folder/public_html/components/com_joomgallery/helpers/helper.php on line 255

Code is like this :

  $text     = preg_replace('/('.$replace2.')/ie', $replace, $text);

Entire code block :

 public static function createPagetitle($text, $catname = '', $imgtitle = '', $page_title = '')
  {
    preg_match_all('/(\[\!.*?\!\])/i', $text, $results);
    define('COM_JOOMGALLERY_COMMON_CATEGORY', JText::_('COM_JOOMGALLERY_COMMON_CATEGORY'));
    define('COM_JOOMGALLERY_COMMON_IMAGE', JText::_('COM_JOOMGALLERY_COMMON_IMAGE'));
    for($i = 0; $i<count($results[0]); $i++)
    {
      $replace  = str_replace('[!', '', $results[0][$i]);
      $replace  = str_replace('!]', '', $replace);
      $replace  = trim($replace);
      $replace2 = str_replace('[!', '\[\!', $results[0][$i]);
      $replace2 = str_replace('!]', '\!\]', $replace2);
      $text     = preg_replace('/('.$replace2.')/ie', $replace, $text);
    }
    $text = str_replace('#cat', $catname, $text);
    $text = str_replace('#img', $imgtitle, $text);
    $text = str_replace('#page_title', $page_title, $text);

    $text = self::addSitenameToPagetitle($text);

    return $text;
  }
Elin
  • 6,507
  • 3
  • 25
  • 47
We are Borg
  • 5,117
  • 17
  • 102
  • 225
  • use `preg_replace_callback` instead like It's explained in this post : https://stackoverflow.com/questions/16986331/can-someone-explain-the-e-regex-modifier – Fky May 29 '18 at 07:58
  • @Fky : Yes, I saw that post already, didn't understood how to modify that code to suit my function. I am new to Joomla, and my code doesn't return like the one in post. Still, I am trying with that patch of code. Here is what I have so far : https://pastebin.com/6synrNuT . Any ideas? – We are Borg May 29 '18 at 08:04

1 Answers1

0

Finally, this code worked :

  $text = preg_replace_callback('/('.$replace2.')/',create_function('$replace','return @replace;'),$text);

Thank you all.

We are Borg
  • 5,117
  • 17
  • 102
  • 225
  • The code block in your question and in your answer look really, really suboptimal. Please provide one or two sample input strings and your desired output for each. I am confident that I can largely clean up your process. – mickmackusa Jun 29 '18 at 00:05