ATLAS LINE CO.,LTD. Call Us : Tel: +66-2-000-3087

Note that allowing anchor labels otherwise href functions opens up various other possible protection hole that the service wouldn’t lessen

means stripUnwantedTagsAndAttrs ( $html_str ) $xml = new DOMDocument (); //Prevents cautions: best error approaching is beyond scope regarding example libxml_use_internal_problems ( genuine ); //Record the latest tags we want to enable it to be here, Mention you need to make it html and body if not entire sequence will be eliminated $allowed_tags = array( “html” , “body” , “b” , “br” , “em” , “hr” , “i” , “li” , “ol” , “p” , “s” , “span” , “table” , “tr” , “td” , “u” , “ul” ); //Record the services we would like to enable it to be right here $allowed_attrs = number ( “class” , “id” , “style” ); when the (! strlen ( $html_str )) in the event that ( $xml -> loadHTML ( $html_str , LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD )) foreach ( $xml -> getElementsByTagName ( “*” ) as $mark ) in the event that (! in_range ( $level -> tagName , $allowed_labels )) $tag -> parentNode -> removeChild ( $tag ); >otherwise foreach ( $level -> qualities because the $attr ) in the event the (! in_number ( $attr -> nodeName , $allowed_attrs )) $tag -> removeAttribute ( $attr -> nodeName ); > > > > > return $xml -> saveHTML ();> ?>

When you need to get appropriate labels upcoming have fun with remove_attrs solution, although it cannot make sure labels is healthy otherwise found in new suitable perspective

Just after upgrading out-of v7.step 3.step 3 to help you v7.step three.seven it looks nested “php labels” to the a sequence are no offered getting stripped accurately by the remove_tags().

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

To have state-of-the-art reasoning contemplate using DOM parser

Features:* allowable tags (like in remove_tags),* elective stripping options that come with the brand new deductible tags,* recommended comment sustaining,* removing busted and you will unclosed labels and you will statements,* elective callback means require each piece processed 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 ( ‘/(