Blog

Observe that enabling point tags otherwise href functions opens up several other possible cover opening that this service would not lessen

means stripUnwantedTagsAndAttrs ( $html_str ) $xml = the fresh DOMDocument (); //Prevents warnings: best mistake dealing with is out of range of analogy libxml_use_internal_errors ( genuine ); //List the latest labels you want to enable it to be here, Note you should allow it to be html and body if you don’t entire string often getting cleaned $allowed_labels = array( “html” , “body” , “b” , “br” , “em” , “hr” , “i” , “li” , “ol” , “p” , “s” , “span” , “table” , “tr” , “td” , “u” , “ul” ); //Listing this new functions we gorgeousbrides.net Han har et godt poeng wish to make it here $allowed_attrs = selection ( “class” , “id” , “style” ); if the (! strlen ( $html_str )) when the ( $xml -> loadHTML ( $html_str , LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD )) foreach ( $xml -> getElementsByTagName ( “*” ) as the $level ) if the (! in_assortment ( $level -> tagName , $allowed_tags )) $level -> parentNode -> removeChild ( $tag ); >otherwise foreach ( $level -> features since the $attr ) if (! in_selection ( $attr -> nodeName , $allowed_attrs )) $tag -> removeAttribute ( $attr -> nodeName ); > > > > > go back $xml -> saveHTML ();> ?>

If you’d like to score appropriate labels then fool around with remove_attrs option, although it does not guarantee tags are well-balanced or included in the brand new appropriate context

Immediately after updating out-of v7.step three.step three so you’re able to v7.3.7 it seems nested “php labels” in to the a sequence are not any longer becoming stripped accurately because of the remove_tags().

$data = ‘Each
NewLine’ ; $new = strip_tags ( $data , ” ); var_dump ( $new ); // OUTPUTS string(11) “EachNewLine” ?>

To have state-of-the-art logic consider using DOM parser

Features:* allowable labels (such as remove_tags),* recommended removing attributes of the new deductible labels,* elective remark sustaining,* removing busted and you can unclosed labels and you may statements,* recommended callback mode call for each piece canned permitting flexible substitutes.

function better_strip_tags ( $str , $allowable_tags = ” , $strip_attrs = false , $preserve_comments = false , callable $callback = null ) $allowable_tags = array_map ( ‘strtolower’ , array_filter ( // lowercase preg_split ( ‘/(?:>|^)\\s*(?: <|$)/'>// filter broken ) ); $comments_and_stuff = preg_split ( ‘/(