RobLab – A script to remove all HTML tags
I mentioned this in a comment I wrote recently, so I thought it was time to add a script to RobLab that removes all HTML tags from an input string.
Enjoy!
I mentioned this in a comment I wrote recently, so I thought it was time to add a script to RobLab that removes all HTML tags from an input string.
Enjoy!
9 Comments/Reactions
July 26th, 2005 at 13:41
This always makes me wonder how I store my own content. WYSIWYG editors in CMS systems like FCKEditor asume that content is always stored with it’s layout formatting when in many cases this in not desired. Handy script, I’ll give it a look see.
July 26th, 2005 at 13:48
Hi Egor,
That was pretty much the reason for me writing this script to begin with. I needed to extract some text without formatting and it was stored with HTML tags mixed in it.
Hopefully it helps you out when needed!
July 26th, 2005 at 14:06
If I’m not mistaken, you forgot to put more
&s to the &’s, for the code example on that page:/*This line is optional, it replaces escaped brackets with real ones,
i.e. is replaced with >
*/
July 26th, 2005 at 14:26
Lim,
Thanks for your comment.
If you mean that the source code of the example page was invalid due to unescaped ampersands, you’re completely right. I’ve fixed that now.
Thanks!
July 27th, 2005 at 3:08
Uh, not I mean, there’s one line there sounds a bit weird:
i.e. < is replaced with < and > is replaced with >
Somehow your commenting system here seems to have problems with HTML entities..
Sorry
July 27th, 2005 at 8:53
Lim,
Ah, now I know what you mean. Yes, that looked a bit misleading, didn’t it?
It’s corrected now, and reads:
< is replaced with < and > is replaced with >And yes, my commenting system can do some weird HTML escaping things sometimes, sorry.
October 30th, 2005 at 2:41
I prefer extending the string object with a new method:
String.prototype.stripHTML = function() {return this.replace(//g, ”);}
Exampe:
var foo = ‘hello robert…’;
alert(foo.stripHTML());
Less code, more handy…
/hbi
October 30th, 2005 at 2:43
Hmm…My regular expression was deleted in the submission… a new try?
String.prototype.stripHTML = function() {return this.replace(/<.*?>/g, ”);}
October 30th, 2005 at 13:13
Hakan,
Absolutely, that’s a nice approach!
Sorry about the code stripping, good that you made it with your second comment.
Write a comment
Twitter reactions