Search code examples
phpjoomla

Jooml : preg_replace is deprecated


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;
  }

Solution

  • Finally, this code worked :

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

    Thank you all.