3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = "<input type=\"text\">\n<img src=\"\"><a href=\"\"><button type=\"button\"></button><div id=\"some\"></div><p></p>"; var_dump(removeTags($str, array('img'))); /** * Strip only certain tags in the given HTML string * @return String */ function removeTags($html, $tags){ $existing_tags = getAllTagNames($html); $allowable_tags = '<'.implode('><', array_diff($existing_tags, $tags)).'>'; return strip_tags($html, $allowable_tags); } /** * Get a list of tag names in the provided HTML string * @return Array */ function getAllTagNames($html){ $tags = array(); $part = explode("<", $html); foreach($part as $tag){ $chunk = explode(" ", $tag); if(empty($chunk[0]) || $chunk[0][0] == "/") continue; $tag = trim($chunk[0], " >"); if(!in_array($tag, $tags)) $tags[] = $tag; } return $tags; }
Output for git.master, git.master_jit, rfc.property-hooks
string(90) "<input type="text"> <a href=""><button type="button"></button><div id="some"></div><p></p>"

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
27.15 ms | 405 KiB | 5 Q