Observe that enabling point labels or href services reveals several other possible defense opening that service won’t prevent

Observe that enabling point labels or href services reveals several other possible defense opening that service won’t prevent

setting stripUnwantedTagsAndAttrs ( $html_str ) $xml = new DOMDocument (); //Inhibits warnings: best mistake addressing is beyond extent off example libxml_use_internal_problems ( genuine ); //Number the labels you want to ensure it is here, Mention you should succeed html and body otherwise entire sequence commonly end up being eliminated $allowed_tags = array( «html» , «body» , «b» , «br» , «em» , «hr» , «i» , «li» , «ol» , «p» , «s» , «span» , «table» , «tr» , «td» , «u» , «ul» ); //Listing new qualities we need to make it here $allowed_attrs = assortment ( «class» , «id» , «style» ); if (! strlen ( $html_str )) when the ( $xml -> loadHTML ( $html_str , LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD )) foreach ( $xml -> getElementsByTagName ( «*» ) as $tag ) in the event the (! in_range ( $mark -> tagName , $allowed_labels )) $tag -> parentNode -> removeChild ( $level ); >else foreach ( $tag -> characteristics because the $attr ) if the (! in_selection ( $attr -> nodeName , $allowed_attrs )) $level -> removeAttribute ( $attr -> nodeName ); > > > > > come back $xml -> saveHTML ();> ?>

Should you want to rating legitimate labels following have fun with remove_attrs option, although it does not guarantee tags was healthy otherwise found in this new appropriate framework

Once updating off v7.step 3.step 3 to v7.3.7 it seems nested «php tags» into the a set are not any extended are stripped correctly by strip_tags().

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

For complex reasoning contemplate using DOM parser

Features:* deductible tags (such as remove_tags),* recommended removing attributes of new deductible tags,* optional comment preserving,* removing broken and you will unclosed tags and you may comments,* optional callback mode need every piece processed making it possible for flexible 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 ( ‘/(

Добавить комментарий