我有php代码:
preg_replace('#<!-- '.(($c)?'\#':'').'BEGIN '.$block.' -->[\r\n]*(.*?)[\r\n]*<!-- '.(($c)?'\#':'').'END '.$block.' -->#se',
'$s = stripslashes("\\1");',$str);
现在我改为:
preg_replace_callback('#<!-- '.(($c)?'\#':'').'BEGIN '.$block.' -->[\r\n]*(.*?)[\r\n]*<!-- '.(($c)?'\#':'').'END '.$block.' -->#s',
function($m){
return $s = stripslashes($m[1]);},
$str);
但不能正常工作,而不是显示错误
帮帮我,谢谢!
这是我加载html文件的功能
var $ext = ".html";
var $cache_temp = array();
function get_htm($filename,$blockname = '',$c = false) {
$full_link = $_SESSION['skin_folder']."/".$filename.$this->ext;
if (!file_exists($full_link)) {
die("Không tìm thấy file : <b>".$full_link."</b>");
}
if ($this->cache_temp['file_'.$filename]) $file_content = $this->cache_temp['file_'.$filename];
else {
$this->cache_temp['file_'.$filename] = $file_content = file_get_contents($full_link);
}
return $file_content;
}
function get_block_from_htm($str,$block = '',$c = false) {
if (!$this->cache_temp['block_'.$block]) {
preg_replace('#<!-- '.(($c)?'\#':'').'BEGIN '.$block.' -->[\r\n]*(.*?)[\r\n]*<!-- '.(($c)?'\#':'').'END '.$block.' -->#se','$s = stripslashes("\1");',$str);
if ($s != $str) $str = $s;
else $str = '';
$this->cache_temp['block_'.$block] = $str;
}
return $this->cache_temp['block_'.$block];
}
和html文件看起来像这样
bot.html
<div class="bloc01 bgd01">
<h2>Bot online now</h2>
<ul class="list01">
<!-- BEGIN bot -->
<!-- #BEGIN bot.row --><div class="tr03"><li>
abc123
</li></div>
<!-- #END bot.row -->
<!-- END bot -->
</ul>
</div>
...
last_search.html
<div class="bloc01 bgd01">
<h2>last_search</h2>
<ul class="list01">
<li>
<!-- BEGIN last_search -->
<!-- #BEGIN last_search.row --> <div class="tr03"><li>
def456
</li></div>
<!-- #END last_search.row -->
<!-- END last_search -->
</li>
</ul>
</div>
...
&#13;
当我改为php7时我需要更新我的代码但是我将代码从preg_replace更改为preg_replace_callback我的代码无法正常运行而不显示错误