setting stripUnwantedTagsAndAttrs ( $html_str ) $xml = the new DOMDocument (); //Prevents cautions: proper error handling is beyond extent of example libxml_use_internal_mistakes ( real ); //Listing the newest labels we would like to create here, Notice you should allow it to be html and the entire body or even entire string tend to end up being removed $allowed_tags = array( “html” , “body” , “b” , “br” , “em” , “hr” , “i” , “li” , “ol” , “p” , “s” , “span” , “table” , “tr” , “td” , “u” , “ul” ); //Listing the fresh characteristics we want to make it here $allowed_attrs = selection ( “class” , “id” , “style” ); when the (! strlen ( $html_str )) when the ( $xml -> loadHTML ( $html_str , LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD )) foreach ( $xml -> getElementsByTagName ( “*” ) because $tag ) if the (! in_number ( $tag -> tagName , $allowed_labels )) $tag -> parentNode -> removeChild ( $mark ); >otherwise foreach ( $mark -> attributes because $attr ) in the event that (! in_range ( $attr -> nodeName , $allowed_attrs )) $level -> removeAttribute ( $attr -> nodeName ); > > > > > return $xml -> saveHTML ();> ?>
If you wish to score legitimate tags then have fun with strip_attrs choice, although it does not make certain labels is actually balanced or included in the brand new suitable perspective
After updating off v7.step Pakistan mladenke three.step three so you can v7.3.seven it looks nested “php labels” inside a set are no longer are removed truthfully by strip_tags().
$data = ‘Each
NewLine’ ; $new = strip_tags ( $data , ” ); var_dump ( $new ); // OUTPUTS string(11) “EachNewLine” ?>
To have advanced logic consider utilizing DOM parser
Features:* deductible tags (as in remove_tags),* recommended removing top features of this new deductible tags,* elective review sustaining,* removing damaged and you may unclosed labels and you may statements,* optional callback form call for every piece canned allowing for flexible substitutes.