1.use preg_replace_callback
举例如下
<?
$str="<div style='background:blue'>i j k</div>";
$pat="/(<div[^>]*>)(.*)(<\/div>)/iU";
function rep($arr){return $arr[1].preg_replace("/ /"," ",$arr[2]).$arr[3];}
$str=preg_replace_callback($pat,rep,$str);
echo $str;
?>
举例如下
<?
$str="<div style='background:blue'>i j k</div>";
$pat="/(<div[^>]*>)(.*)(<\/div>)/iU";
function rep($arr){return $arr[1].preg_replace("/ /"," ",$arr[2]).$arr[3];}
$str=preg_replace_callback($pat,rep,$str);
echo $str;
?>
$content="<table border>\r\n<tr>\r\n<td>ha\r\nhe\r\nhi</td>\r\n</tr>\r\n</table>\r\n";
$content=preg_replace("/(?<!>)\r\n/iU","<br>",$content);
echo $content;