mode stripUnwantedTagsAndAttrs ( $html_str ) $xml = new DOMDocument (); //Inhibits cautions: right error dealing with may be out of extent off analogy libxml_use_internal_mistakes ( real ); //Checklist the tags we want to succeed here, Note you ought to ensure it is html and the entire body if you don’t entire string usually getting removed $allowed_tags = array( „html“ , „body“ , „b“ , „br“ , „em“ , „hr“ , „i“ , „li“ , „ol“ , „p“ , „s“ , „span“ , „table“ , „tr“ , „td“ , „u“ , „ul“ ); //Listing the fresh functions we need to succeed right greek beautiful women here $allowed_attrs = variety ( „class“ , „id“ , „style“ ); in the event that (! strlen ( $html_str )) if ( $xml -> loadHTML ( $html_str , LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD )) foreach ( $xml -> getElementsByTagName ( „*“ ) once the $level ) in the event the (! in_selection ( $tag -> tagName , $allowed_tags )) $level -> parentNode -> removeChild ( $mark ); >more foreach ( $mark -> properties because the $attr ) when the (! in_assortment ( $attr -> nodeName , $allowed_attrs )) $mark -> removeAttribute ( $attr -> nodeName ); > > > > > return $xml -> saveHTML ();> ?>
If you’d like to get valid tags after that use remove_attrs option, although it doesn’t make sure tags try well-balanced or found in the brand new appropriate framework
Immediately after upgrading off v7.step three.step three in order to v7.step 3.seven it appears nested „php tags“ inside a sequence are no offered getting stripped truthfully from the remove_tags().
$data = ‚Each
NewLine‘ ; $new = strip_tags ( $data , “ ); var_dump ( $new ); // OUTPUTS string(11) „EachNewLine“ ?>
Getting advanced reasoning consider using DOM parser
Features:* deductible tags (as with remove_tags),* elective removing features of the fresh new allowable labels,* recommended feedback sustaining,* deleting busted and unclosed tags and comments,* optional callback form call for every piece canned permitting versatile alternatives.
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 ( ‚/(
Schreibe einen Kommentar