ホームページ  >  記事  >  バックエンド開発  >  preg_replace_callback使用的有关问题

preg_replace_callback使用的有关问题

WBOY
WBOYオリジナル
2016-06-13 12:01:55791ブラウズ

preg_replace_callback使用的问题
$pattern = array(
            '//', // 替换smarty注释
            '//',               // 替换不换行的html注释
            '/(href=["|\'])\.\.\/(.*?)(["|\'])/i',  // 替换相对链接
            '/((?:background|src)\s*=\s*["|\'])(?:\.\/|\.\.\/)?(images\/.*?["|\'])/is', // 在images前加上 $tmp_dir
            '/((?:background|background-image):\s*?url\()(?:\.\/|\.\.\/)?(images\/)/is', // 在images前加上 $tmp_dir
            '/{nocache}(.+?){\/nocache}/ise', //无缓存模块
            );
        $replace = array(
            '\1',
            '',
            '\1\2\3',
            '\1' . $tmp_dir . '\2',
            '\1' . $tmp_dir . '\2',
            "'{insert name=\"nocache\" ' . '" . $this->_echash . "' . base64_encode('\\1') . '}'",
            );

        return preg_replace($pattern, $replace, $source);

因为preg_replace被废弃了,使用preg_replace_callback替换应该怎么写啊?大侠指导一下好吗?
------解决方案--------------------
把有 /e 属性的拿出来单做

 $source = preg_replace_callback(<br />   '/{nocache}(.+?){\/nocache}/is', <br />   create_function('$r', "'{insert name=\"nocache\" ' . '" . $this->_echash . "' . base64_encode($r[1]) . '}'"),<br />   $source);

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。