现在困到将数组放回,我用现在循环,使用替换函数替换回去。
这样就遇到了问题,
使用
preg_replace可以保留上面(htmlentities,nl2br)的处理,但是所有匹配值都成了数组的最后已项,如果使用
str_replace,可以将所有匹配值都放回原来的地方,但是(htmlentities,nl2br)的处理都失效了。下面是这个思路的代码。
<?php
function ubb_php($tex){
preg_match_all("/\[code\]([\s\S]*?)\[\/code\]/si",$tex,$code);
$code=$code[0];
$code = array_map("htmlentities",$code);
$code = array_map("nl2br",$code);
foreach($code as $key =>$value){
print_r($value);echo '<br>';
$tex = preg_replace("/\[code\]([\s\S]*?)\[\/code\]/si",$value,$tex);
//$tex = str_replace("/\[code\]([\s\S]*?)\[\/code\]/si",$value,$tex);
}
return $tex;
//return $code;
}
$c = ubb_php("sadfaffs[*code]<b>ddd</b><span style=\"color: #0000BB\">hello,
good</span>[/*code]ddsddddfafef[*code]<span style=\"color: #0000BB\">hello,g
adffda d</span>[/*code]dfaewfadfa");
print_r($c);
var_dump($c); [code]里的*字是为了不被处理,各位看官研究的时候自动略去。 最佳答案