If its necessary to clean all HTML tags and JS scripts from any content next PHP function will do the job:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | /** * Properly strip all HTML tags including script and style * * This differs from strip_tags() because it removes the contents of * the `<script>` and `<style>` tags. E.g. `strip_tags( '<script>something</script>' )` * will return 'something'. wp_strip_all_tags will return '' * * @since 2.9.0 * * @param string $string String containing HTML tags * @param bool $remove_breaks optional Whether to remove left over line breaks and white space chars * @return string The processed string. */ function wp_strip_all_tags($string, $remove_breaks = false) { $string = preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $string ); $string = strip_tags($string); if ( $remove_breaks ) $string = preg_replace('/[\r\n\t ]+/', ' ', $string); return trim( $string ); } |
