Skip to main content
March 6, 2007
Question

remove html tags from a string

  • March 6, 2007
  • 2 replies
  • 333 views
Hi, is there a simple way to get rid of html tags present on a string? What about special chars encoded? What I want to do is to change

<p>Hi, this is a <b>tagged html</b> text with some special chars: &aacute;&Aacute;&ccedil;...</p>

into this:

Hi, this is a tagged html text with some special chars: áÁç...

The formatting information, like the bold on text above, is not important to me. I just want the plain text with special chars converted.
This topic has been closed for replies.

2 replies

Inspiring
March 6, 2007
A fairly painless solution to stripping out html tags is below. After you strip them out, you'll still need to take care of those special characters. You can do that with the prototypable method outlined here:
http://www.actionscript.org/forums/showthread.php3?t=111952



Inspiring
March 6, 2007
Lujunq,

> Hi, is there a simple way to get rid of html tags present on
> a string?

You betcha. Just route the string with those tags to the TextField.text
property of your text field, rather than its TextField.htmlText property.

> What about special chars encoded? What I want to do is
> to change
> <p>Hi, this is a tagged html text with some special chars:
> &aacute;&Aacute;&ccedil;...</p>

Ah, those are HTML entities, and Flash only supports very few of them.
Search "About supported HTML entities" in the documentation for the full
(very short) list.

> The formatting information, like the bold on text above, is
> not important to me. I just want the plain text with special
> chars converted.

HTML formatting is required to translate the few HTML entities
supported. If you drop the HTML formatting, you'll lose the formatting, but
you'll also lose the entity conversion. It would be tedious, but you would
have to loops through your string characters looking for HTML entities and
replace them one by one.


David Stiller
Adobe Community Expert
Dev blog, http://www.quip.net/blog/
"Luck is the residue of good design."