Ask a Question related to Macromedia Flex General Discussion, Design and Development.
-
mstilli@gmail.com #1
strip html tags from textarea content
Hi,
I'm really new to flex developing, I'm writing a page that have to
retrieve some content from an xml file and display it in some form
elements.
I would know if exist some way to strip the tags (Html in this case)
from the text that I will later display in a textarea possibly via some
dom-ajax method.
I tryied to google for this before posting here but found nothing.
thanks
marcello stillitano
mstilli@gmail.com Guest
-
note 33993 added to function.strip-tags
Judging from the sheer number of "holes" found in the posted samples, clearly, creating "safe" html is a difficult task. Consider an alternative... -
Strip html tags
Thanks Kindler, I'm sure it will, but I get a strange error when trying :( I'll figure something out. Cheers, Rob http://robgt.com/... -
note 33826 modified in function.strip-tags by didou
To eminate the script tags found in html, don't use the preg_replace approach. The .* can include </script> when there are multiple script tags, and... -
note 33836 added to function.strip-tags
Correction: the line that reads $second = substr($html, $pos2 + 1); should read $second = substr($html, $pos2); ---- Manual Page --... -
note 33580 added to function.strip-tags
For fixing the <scr<script></script>ipt> bug, wouldn't it be ok to call strip_tags iteratively until the string does not change anymore? ----... -
Unregistered #2
Re: strip html tags from textarea content
public static function stripHtmlTags(html:String, tags:String = ""):String
{
var tagsToBeKept:Array = new Array();
if (tags.length > 0)
tagsToBeKept = tags.split(new RegExp("\\s*,\\s*"));
var tagsToKeep:Array = new Array();
for (var i:int = 0; i < tagsToBeKept.length; i++)
{
if (tagsToBeKept[i] != null && tagsToBeKept[i] != "")
tagsToKeep.push(tagsToBeKept[i]);
}
var toBeRemoved:Array = new Array();
var tagRegExp:RegExp = new RegExp("<([^>\\s]+)(\\s[^>]+)*>", "g");
var foundedStrings:Array = html.match(tagRegExp);
for (i = 0; i < foundedStrings.length; i++)
{
var tagFlag:Boolean = false;
if (tagsToKeep != null)
{
for (var j:int = 0; j < tagsToKeep.length; j++)
{
var tmpRegExp:RegExp = new RegExp("<\/?" + tagsToKeep[j] + "( [^<>]*)*>", "i");
var tmpStr:String = foundedStrings[i] as String;
if (tmpStr.search(tmpRegExp) != -1)
tagFlag = true;
}
}
if (!tagFlag)
toBeRemoved.push(foundedStrings[i]);
}
for (i = 0; i < toBeRemoved.length; i++)
{
var tmpRE:RegExp = new RegExp("([\+\*\$\/])","g");
var tmpRemRE:RegExp = new RegExp((toBeRemoved[i] as String).replace(tmpRE, "\\$1"),"g");
html = html.replace(tmpRemRE, "");
}
return html;
}Unregistered Guest



Reply With Quote

