0

I have a bunch of textareas that I am currently using ckeditor on, and storing the values in a database. When I get these values back, I want to be able to tell if nothing was entered into a particular textarea. The problem however is that ckeditor likes to put its own markup and other things into the string even if that textarea was not touched.

So, I need to be able to remove all spaces, line breaks, and html breaks from the beginning and end of a string (since we do not want to erase the good data). Here are the strings I am currently trying to trim (var_dumped from an array),

array(3) {
  ["remediation"]=>
  string(26) "


    But not the third
"
  ["effective"]=>
  string(28) "


    Second one is blank
"
  ["celebrate"]=>
  string(6) "
"
}

I have already tried the following: trim, this preg replace, and a number of variations of that preg_replace.

Community
  • 1
  • 1
Metropolis
  • 6,542
  • 19
  • 56
  • 86

1 Answers1

2

You can just use trim , strip_tags with array_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);

Output

array
  'remediation' => string 'But not the third' (length=17)
  'effective' => string 'Second one is blank' (length=19)
  'celebrate' => string '' (length=0)
Baba
  • 94,024
  • 28
  • 166
  • 217
  • This is not changing anything, which I am assuming is because of the html in the strings. The first and second element have p tags around them which is fine, but the last has a
    in it which needs to go away also.
    – Metropolis Sep 21 '12 at 22:08
  • Yeah im an idiot, I JUST thought about doing that 5 minutes ago. Not sure why the option did not come to mind in the last 2 hours. I think I have been staring at my screen to long today lol. Thanks for your help man. – Metropolis Sep 21 '12 at 22:18
  • In my case I am actually going to use a temp variable, strip the tags and check the length individually instead of doing it on the whole array, but its the same type of thing. I dont actually want to REMOVE the markup. Just check against it. – Metropolis Sep 21 '12 at 22:19