Skip to Content

Gareth53.co.uk - the online home of Gareth Senior

Stripping HTML

2:16p.m., Sat 6 Jan 2007

Some while ago I was asked to build a flash widget that used an XML feed as its datasource. Annoyingly, the XML feed had html tags in there to format the data. Curses! So I wrote this little actionscript function to strip the HTML. It works in javascript too and I've re-used it a few times since....

function stripHtml(str) {
while ((str.indexOf('<')!=-1) && (toStrip.indexOf('>')!=-1)) {
str = str.slice(0,str.indexOf('<')) + str.slice((str.indexOf('>') + 1),str.length);
}
return str; }

Latest Posts

Blog Categories