I've seen a lot of expressions to remove a specific tag (or many specified tags), and one to remove all but one specific tag, but I haven't found a way to remove all except many excluded (i.e. all except p, b, i, u, a, ul, ol, li
) in PHP. I'm far from good with regex, so I'd need a hand. :) Thanks!
The strip_tags() function strips a string from HTML, XML, and PHP tags. Note: HTML comments are always stripped. This cannot be changed with the allow parameter. Note: This function is binary-safe.
Strip_tags() is a function that allows you to strip out all HTML and PHP tags from a given string (parameter one), however you can also use parameter two to specify a list of HTML tags you want.
To strip out all the HTML tags from a string there are lots of procedures in JavaScript. In order to strip out tags we can use replace() function and can also use . textContent property, . innerText property from HTML DOM.
stripHtml( html ) Changes the provided HTML string into a plain text string by converting <br> , <p> , and <div> to line breaks, stripping all other tags, and converting escaped characters into their display values.
you can do this by usingstrip_tags
function
¶ strip_tags — Strip HTML and PHP tags from a string
strip_tags($contant,'tag you want to allow');
like
strip_tags($contant,'<code><p>');
strip_tags()
does exactly this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With