CKeditor remove extra whitespace

两盒软妹~` 提交于 2021-01-27 07:06:37

问题


I'm using CKeditor for a text editor and it won't remove extra whitespace.

I've tried

$foo = strip_tags($foo);
$foo = preg_replace('/\s+/',' ',$foo);

I don't know of any other way to remove whitespace from here. Any ideas?

Thanks


回答1:


try these:

$foo = preg_replace('/\s{2,}/', ' ', $foo);

or

$foo = preg_replace('/( )+/', ' ', $foo);

or this one removes line breaks too

$foo = trim(preg_replace('/[\s\t\n\r\s]+/', ' ', $foo))

Update

Try this one:

$foo = trim(preg_replace('/( )+|\s\K\s+/','',$foo));



回答2:


Solved If anybody is curious, I solved this by cleaning them before they went into the database.

  $cpbody = trim($_POST['cbody']);

  $cpbody = preg_replace("/\<p\>\&nbsp\;\<\/p\>/", "", $cpbody);
  $cpbody = preg_replace("/\&nbsp\;+/", " ", $cpbody);
  $cpbody = preg_replace("/\s+/", " ", $cpbody);

  $cpbody = htmlentities($cpbody);


来源:https://stackoverflow.com/questions/24579078/ckeditor-remove-extra-whitespace

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!