Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whether there is something similar to strip_tags in Java?

Tags:

java

android

We have a function strip_tags in PHP which would strip all the tags and also you can exempt certain tags from being stripped out..

My question is whether there is anything similar in Java??

like image 988
Shan Avatar asked Jan 20 '23 03:01

Shan


1 Answers

You could try using the JSoup library. That API provides a clean method:

For examples, have a look over here: Sanitize untrusted HTML:

String unsafe = 
  "<p><a href='http://example.com/' onclick='stealCookies()'>Link</a></p>";

String safe = Jsoup.clean(unsafe, Whitelist.basic());

// now: <p><a href="http://example.com/" rel="nofollow">Link</a></p>
like image 131
aioobe Avatar answered Jan 29 '23 13:01

aioobe