过滤换行符问题

helloshihaiping 2011-09-02 09:45:21
怎么过滤掉ckeditor自带的换行符<p></p>
每次从数据库读出来都给我换行 太难看了
...全文
530 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
yt2626 2011-09-02
  • 打赏
  • 举报
回复
用包含div及css
helloshihaiping 2011-09-02
  • 打赏
  • 举报
回复
哎 能不能给段代码啊 我也知道些过滤器的 急死人啦 老是给我换行 正没法整了
  • 打赏
  • 举报
回复
我记得可以配置的啊。。如果实在不爽,可以用kindeditor。。。或者直接str.replaceAll("<p>","");
BearKin 2011-09-02
  • 打赏
  • 举报
回复
[Quote=引用楼主 helloshihaiping 的回复:]
怎么过滤掉ckeditor自带的换行符<p></p>
每次从数据库读出来都给我换行 太难看了
[/Quote]
你可以写个过滤器 在每次提交数据的时候将所有的参数获得到并且逐个将<p>过滤掉

没记错的话是可以在ckeditor中设置的 最近问这类问题的人太多了...
helloshihaiping 2011-09-02
  • 打赏
  • 举报
回复
怎么不说关键呢 关键我不知道怎么用啊 高手指点一下
yuanyu113 2011-09-02
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 izard999 的回复:]
用正则表达式替换下
[/Quote] 赞一个
izard999 2011-09-02
  • 打赏
  • 举报
回复
用正则表达式替换下
helloshihaiping 2011-09-02
  • 打赏
  • 举报
回复
<p>
<img alt="" src="/zhongguan_company/userfiles/images/59.jpg" /></p>
我说错了,不是去掉图片标签,就是上面的,从数据库读出来的图片也自动换行
paneyjiang 2011-09-02
  • 打赏
  • 举报
回复
类似这种content = content.replaceAll("<img> </img>", "");
paneyjiang 2011-09-02
  • 打赏
  • 举报
回复
图片哇,你可能还需要加一些去掉图片标签的方法了,
helloshihaiping 2011-09-02
  • 打赏
  • 举报
回复
你这个方法用在文本上是可以的,为什么用在过滤图片就不行了?
helloshihaiping 2011-09-02
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 paneyjiang 的回复:]
Java code

public String dropHtml(String content) {
// <p>段落替换为换行
content = content.replaceAll("<p .*?>", "\r\n");
// <br><br/>替换为换行
content = content.replaceAll(……
[/Quote]
谢谢你 ,解决了,这是对你的感谢
paneyjiang 2011-09-02
  • 打赏
  • 举报
回复

public String dropHtml(String content) {
// <p>段落替换为换行
content = content.replaceAll("<p .*?>", "\r\n");
// <br><br/>替换为换行
content = content.replaceAll("<br\\s*/?>", "\r\n");
// 去掉其它的<>之间的东西
content = content.replaceAll("\\<.*?>", "");
// 还原HTML
// content = HTMLDecoder.decode(content);
return content;
}
helloshihaiping 2011-09-02
  • 打赏
  • 举报
回复
有哪位大虾贴出段代码啊

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧