php提交表单时保留多个空格及换行的文本样式的方法
需求是:用户提交表单时屏蔽敏感词的功能。其中敏感词来自服务器端同一路径下的ciku.txt,敏感词通过"|"连接,例如"g|c|a",提交表单时替换敏感词,更重要的是,需要保持表单文本域中用户输入的多个空格及换行的样式,并原样输出。php代码如下:
');
$message=preg_replace($pattern, $replace, $_POST['message']);
$cikuStr=file_get_contents('ciku.txt');
$cikuArr=explode('|',$cikuStr);
$liuyan=str_replace($cikuArr, "**",$message);
echo '您的留言是:
'.$liuyan;
}
?>
1