The original code for preg_replace to rewrite preg_replace_callback is as follows:
$ Pattern = array ('/
/', // Replace the smarty comment '/
/', // Replace the html comment without line breaks'/(href = ["| \ ']) \. \. \/(. *?) (["| \ '])/I', // replace the relative link '/((? : Background | src) \ s * = \ s * ["| \ ']) (? : \. \/| \.\.\/)? (Images \/.*? ["| \ '])/Is', // add $ tmp_dir '/((? : Background | background-image): \ s *? Url \()(? : \. \/| \.\.\/)? (Images \/)/is ', // add $ tmp_dir'/{nocache} (. +?) to images ?) {\/Nocache}/ise ', // no Cache module); $ 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 );
The original server is php5.2. after being upgraded to php5.5, a program error is found.
Reply to discussion (solution)
$ Pattern = array ('/
/', // Replace the smarty comment '/
/', // Replace the html comment without line breaks'/(href = ["| \ ']) \. \. \/(. *?) (["| \ '])/I', // replace the relative link '/((? : Background | src) \ s * = \ s * ["| \ ']) (? : \. \/| \.\.\/)? (Images \/.*? ["| \ '])/Is', // add $ tmp_dir '/((? : Background | background-image): \ s *? Url \()(? : \. \/| \.\.\/)? (Images \/)/is ', // add $ tmp_dir before images); $ 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 );