解决方案 »

  1.   

            $pattern = array(
                '/<!--[^>|\n]*?({.+?})[^<|{|\n]*?-->/', // 替换smarty注释
                '/<!--[^<|>|{|\n]*?-->/',               // 替换不换行的html注释
                '/(href=["|\'])\.\.\/(.*?)(["|\'])/i',  // 替换相对链接
                '/((?:background|src)\s*=\s*["|\'])(?:\.\/|\.\.\/)?(images\/.*?["|\'])/is', // 在images前加上 $tmp_dir
                '/((?:background|background-image):\s*?url\()(?:\.\/|\.\.\/)?(images\/)/is', // 在images前加上 $tmp_dir
                );
            $replace = array(
                '\1',
                '',
                '\1\2\3',
                '\1' . $tmp_dir . '\2',
                '\1' . $tmp_dir . '\2',
                );        $source = preg_replace($pattern, $replace, $source);
            return preg_replace_callback('/{nocache}(.+?){\/nocache}/is', function($m) {
                return '{insert name="nocache" ' . $this->echash . base64_encode($m[1]) . '}';
            }, $source);