1

It's seems quite simple - strip_tags($string);

But I will repeat - html tags

With use of strip tags for example

"THIS<THISTHISTHIS" >> THIS

Or

$str = "You can write 'more' as < sign" >> "You can write 'more' as "

or

strip_tags("you know that 5<8"); //cuts '8'

and I dont want it.

I know that basicly <everything> can be tag in html, but I want to remove those default html tags

4 Answers 4

1

So why don't use put the tags you want to keep in a string and call strip_tags

$keep = '<a><div><span>';
$new_html = strip_tags($html, $keep);
Sign up to request clarification or add additional context in comments.

3 Comments

$keep = '<a><div><span>';echo strip_tags("you know that 5<8", $keep); cuts 8
So maybe add <8> to your whitelist?
you can htmlspecialchars your content using a dom parser first.
1

You can use strip_tags() with a whitelist:

strip_tags($str,'<code><em><p>');

Alternatively, you could use an HTML parser like this one for removing the HTML tags.

Hope this helps!

Comments

0

You could specify which tags you will allow in the second argument of strip_tags:

string strip_tags ( string $str [, string $allowable_tags ] )

Comments

0

Check HTMLPurifier: http://htmlpurifier.org/

A bit hard in customization, but it gives very good filtering of html and css.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.