HTML Cleaner Store

Is there a way to force the HTML cleaner to preserve the implication spaces that are normally visible in rendered HTML?

For example, you usually expect a space between Fooand Barin the following cases:

Foo<br/>Bar

Example 1

<div>Foo</div><div>Bar</div>

Example 2

+4
source share
2 answers

I have a cruel plan - replace any tag that closes the ">" with a space, and remove the double spaces

<?php
$text = '<div>test</div><div>me</div>';

$text = preg_replace('/(<\/[a-z]+>)/', '$1 ', $text);
$text = trim(preg_replace('/\s+/', ' ', strip_tags($text)));

var_dump($text);

Returns

string(7) "test me"
+1
source

It seems that HTMLPurifier does not remove spaces, it removes tags together because it does not recognize them (which is strange).

Concerning Foo<br/>Bar

  • Error Line 1, Column 3: Unrecognized <br /> tag removed

Concerning <div>Foo</div><div>Bar</div>

  • Error Line 1, Column 0: Unrecognized <div> tag removed
  • Error Line 1, Column 8: Unrecognized </div> tag removed
  • Error Line 1, Column 14: Unrecognized <div> tag removed
  • Error Line 1, Column 22: Unrecognized </div> tag removed

This can be seen by enabling CollectErrors in Live Demo.

enter image description here

, div br: http://htmlpurifier.org/live/configdoc/plain.html#HTML.AllowedElements

Live Demo:

enter image description here

+1

All Articles