前景提要
HDC调试需求开发(15万预算),能者速来!>>>
本人是PHP的入门者,不会。最近搭建了ECSHOP程序,但使用了PHP5.6,函数preg_replace要全部改成preg_replace_call。不会,这里摘取了几段,希望能给予帮助!!
谢谢各位大神了!!!
$out = "<?php \n" . '$k = ' . preg_replace("/(\'\\$[^,]+)/e" , "stripslashes(trim('\\1','\''));", var_export($t, true)) . ";\n"; $val = preg_replace("/\[([^\[\]]*)\]/eis", "'.'.str_replace('$','\$','\\1')", $val); $source = preg_replace_callback ( $pattern , function ( $r ){ return '{include file=' . strtolower ( $r [ 1 ]). '}' ;}, $source ); $source = preg_replace ( $pattern , $reg_content , $source ); source = preg_replace('/<head>/i', "<head>\r\n<meta name=\"Generator\" content=\"" . APPNAME .' ' . VERSION . "\" />", $source); $source = preg_replace ( '/<head>/i' , "<head> \r\n <base href= \" " . $GLOBALS [ 'ecs' ]->url() . " \" />" , $source ); $source = preg_replace ( '/(<link\shref=["| \' ])(?:\.\/|\.\.\/)?(css\/)?([a-z0-9A-Z_]+\.css["| \' ]\srel=["| \' ]stylesheet["| \' ]\stype=["| \' ]text\/css["| \' ])/i' , '\1' . $tmp_dir . '\2\3' , $source ); $source = preg_replace ( '/(<script\s(?:type|language)=["| \' ]text\/javascript["| \' ]\ssrc=["| \' ])(?:\.\/|\.\.\/)?(js\/[a-z0-9A-Z_\-\.]+\.(?:js|vbs)["| \' ]><\/script>)/' , '\1' . $tmp_dir . '\2' , $source ); $source = preg_replace ( '/<meta\shttp-equiv=["| \' ]Content-Type["| \' ]\scontent=["| \' ]text\/html;\scharset=(?:.*?)["| \' ][^>]*?>\r?\n?/i' , '<meta http-equiv="Content-Type" content="text/html; charset=' . EC_CHARSET . '" />' . " \n " , $source ); $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 '/([ \' |"])\.\.\//is' , // 以../开头的路径全部修正为空 ); $replace = array ( '\1' , '' , '\1\2\3' , '\1' . $tmp_dir . '\2' , '\1' . $tmp_dir . '\2' , '\1' ); return preg_replace ( $pattern , $replace , $source );