Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://ideone.com/aoOOUN" rel="nofollow">http://ideone.com/aoOOUN</a></p> <p>This function will strip an element of disallowed sub elements, clean its "stripped" sub elements, and leave the rest (recursively).</p> <pre><code>function clean($element, $allowed, $stripped){ if(!is_array($allowed) || ! is_array($stripped)) return; if(!$element)return; $toDelete = array(); foreach($element-&gt;childNodes as $child){ if(!isset($child-&gt;tagName))continue; $n = $child-&gt;tagName; if ($n &amp;&amp; !in_array($n, $allowed) &amp;&amp; !in_array($n, $stripped)){ $toDelete[] = $child; continue; } if($n &amp;&amp; in_array($n, $stripped)){ $attr = array(); foreach($child-&gt;attributes as $a) $attr[] = $a-&gt;nodeName; foreach($attr as $a) $child-&gt;removeAttribute($a); } clean($child, $allowed, $stripped); } foreach ($toDelete as $del) $element-&gt;removeChild($del); } </code></pre> <p>This is the code to clean your string:</p> <pre><code>$xhtml = '&lt;p style="width: 250px;"&gt;This is some text&lt;div class="button"&gt;This is the button&lt;/div&gt;&lt;br&gt;&lt;img src="waves.jpg" width="150" height="200" /&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Title&lt;/b&gt;&lt;br&gt;Here is some more text and &lt;a href="#" target="_blank"&gt;this is a link&lt;/a&gt;&lt;/p&gt;'; $dom = new DOMDocument(); $dom-&gt;loadHTML($xhtml); $body = $dom-&gt;getElementsByTagName('body')-&gt;item(0); clean($body, array('img', 'a'), array('p', 'br', 'b')); echo preg_replace('#^.*?&lt;body&gt;(.*?)&lt;/body&gt;.*$#s', '$1', $dom-&gt;saveHTML($body)); </code></pre> <p>You should check out the Documentation for <a href="http://www.php.net/manual/en/book.dom.php" rel="nofollow">PHP's DOM classes</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload