note 118295 added to function.strip-tags

From: Date: Tue, 10 Nov 2015 13:36:45 +0000
Subject: note 118295 added to function.strip-tags
Groups: php.notes 
Request: Send a blank email to php-notes+get-204132@lists.php.net to get a copy of this message
my function to remove specific tags with the content and can remove elements with attributes <?php function strip_selected_tags_content( $text, $tags = array() ) { foreach ( $tags as $key => $val ) { if ( ! is_array( $val ) ) { $text = preg_replace( '/<' . $val . '[^>]*>([\s\S]*?)<\/' . $val . '[^>]*>/', '', $text ); } else { $text = preg_replace( '/<' . $val[0] . ' ' . $val[1] . '[^>]*>([\s\S]*?)<\/' . $val[0] . '[^>]*>/', '', $text ); } } return $text; } ?> example: <?php $clear = array('social', 'script', 'noindex', 'time', 'header', array( 'div', 'class="tags"' ), array( 'div', 'class="box_comments"' ), array( 'p', 'class="form-submit"' ), array( 'div', 'class="comment-form-comment"' ) ) text = '<preheader>image article</preheader> <header>nnnnn</header> <social>fb code, google code etc...</social> etc.... <p class="text"> bla-bla bla-blabla-bla bla-blabla-bla bla-bla </p> <div>sdasda</div> <div class="tags">true code, that code</div> <div calss="comment-form-comment"> coment form on blog</div> '; echo strip_selected_tags_content($text, $clear); ?> output: <?php <preheader>image article</preheader> etc.... <p class="text"> bla-bla bla-blabla-bla bla-blabla-bla bla-bla </p> <div>sdasda</div> ?> ---- Server IP: 72.52.91.14 Probable Submitter: 37.233.63.70 ---- Manual Page -- http://php.net/manual/en/function.strip-tags.php Edit -- https://master.php.net/note/edit/118295 Del: integrated -- https://master.php.net/note/delete/118295/integrated Del: useless -- https://master.php.net/note/delete/118295/useless Del: bad code -- https://master.php.net/note/delete/118295/bad+code Del: spam -- https://master.php.net/note/delete/118295/spam Del: non-english -- https://master.php.net/note/delete/118295/non-english Del: in docs -- https://master.php.net/note/delete/118295/in+docs Del: other reasons-- https://master.php.net/note/delete/118295 Reject -- https://master.php.net/note/reject/118295 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#204132) next »