代码之家  ›  专栏  ›  技术社区  ›  We are Borg

jooml:preg_replace已弃用

  •  1
  • We are Borg  · 技术社区  · 8 年前

    我正在修改一个joomla模板,并收到此警告。

    deprecated:preg_replace():不推荐使用/e修饰符,请使用 preg_replace_callback而不是in /主页/文件夹/public_html/components/com_joomgallery/helpers/helper.php 在线255

    代码如下:

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

    整个代码块:

     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;
      }
    
    1 回复  |  直到 8 年前
        1
  •  0
  •   We are Borg    8 年前

    最后,此代码起作用:

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

    谢谢大家。

    推荐文章