Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从ckeditor生成的字符串中删除所有空格、换行符和html换行符_Php_Regex_Ckeditor - Fatal编程技术网

Php 从ckeditor生成的字符串中删除所有空格、换行符和html换行符

Php 从ckeditor生成的字符串中删除所有空格、换行符和html换行符,php,regex,ckeditor,Php,Regex,Ckeditor,我有一堆文本区域,我目前正在使用ckeditor,并将这些值存储在数据库中。当我找回这些值时,我想知道是否在特定的文本区域中没有输入任何内容。但问题是,即使文本区域没有被触动,ckeditor也喜欢将自己的标记和其他内容放入字符串中 因此,我需要能够删除字符串开头和结尾的所有空格、换行符和html换行符(因为我们不想删除好的数据)。以下是我当前尝试修剪的字符串(从数组转储的var_) 我已经尝试过以下方法:trim,以及preg\u replace的许多变体。您只需使用trim,strip\u标

我有一堆文本区域,我目前正在使用ckeditor,并将这些值存储在数据库中。当我找回这些值时,我想知道是否在特定的文本区域中没有输入任何内容。但问题是,即使文本区域没有被触动,ckeditor也喜欢将自己的标记和其他内容放入字符串中

因此,我需要能够删除字符串开头和结尾的所有空格、换行符和html换行符(因为我们不想删除好的数据)。以下是我当前尝试修剪的字符串(从数组转储的var_)


我已经尝试过以下方法:trim,以及preg\u replace的许多变体。

您只需使用
trim
strip\u标签
array\u map

$array = array("remediation" => "


    <p> But not the third </p>
","effective" => "


    Second one is blank
","celebrate" => "
");

$array = array_map("strip_tags", $array);
$array = array_map("trim", $array);
var_dump($array);

这并没有改变任何东西,我假设这是因为字符串中的html。第一个和第二个元素周围有p标签,这很好,但最后一个元素中有一个
也需要消失。是的,我是个白痴,我5分钟前就想这么做。不知道为什么在过去的两个小时里没有想到这个选项。我想我今天一直盯着我的屏幕看得太长了,哈哈。谢谢你的帮助。在我的例子中,我实际上要使用一个临时变量,去掉标签并单独检查长度,而不是在整个阵列上进行检查,但这是同一类型的事情。我实际上不想删除标记。检查一下。
$array = array("remediation" => "


    <p> But not the third </p>
","effective" => "


    Second one is blank
","celebrate" => "
");

$array = array_map("strip_tags", $array);
$array = array_map("trim", $array);
var_dump($array);
array
  'remediation' => string 'But not the third' (length=17)
  'effective' => string 'Second one is blank' (length=19)
  'celebrate' => string '' (length=0)