function stripUnwantedTagsAndAttrs ( $html_str ) $xml = the latest DOMDocument (); //Prevents cautions: best error addressing is beyond scope out of example libxml_use_internal_problems ( true ); //Record brand new labels we need to enable it to be here, Note you ought to enable it to be html and body if not entire string will end up being eliminated https://gorgeousbrides.net/no/find-asian-beauty/ $allowed_tags = array( «html» , «body» , «b» , «br» , «em» , «hr» , «i» , «li» , «ol» , «p» , «s» , «span» , «table» , «tr» , «td» , «u» , «ul» ); //List brand new attributes we wish to succeed right here $allowed_attrs = selection ( «class» , «id» , «style» ); in the event the (! strlen ( $html_str )) in the event that ( $xml -> loadHTML ( $html_str , LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD )) foreach ( $xml -> getElementsByTagName ( «*» ) once the $tag ) if (! in_array ( $tag -> tagName , $allowed_labels )) $level -> parentNode -> removeChild ( $mark ); >otherwise foreach ( $level -> services since $attr ) in the event the (! in_range ( $attr -> nodeName , $allowed_attrs )) $mark -> removeAttribute ( $attr -> nodeName ); > > > > > return $xml -> saveHTML ();> ?>
Once updating out-of v7.step three.step three so you can v7.3.seven it appears nested «php tags» inside a string are not any lengthened are removed correctly from the strip_tags().
$data = ‘Each
NewLine’ ; $new = strip_tags ( $data , » ); var_dump ( $new ); // OUTPUTS string(11) «EachNewLine» ?>
Features:* allowable labels (like in remove_tags),* recommended removing attributes of this new deductible labels,* elective review preserving,* removing damaged and unclosed labels and statements,* optional callback means call for every piece canned enabling flexible replacements.
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 ( ‘/(