strip html tags from textarea content

Ask a Question related to Macromedia Flex General Discussion, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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/...
    3. 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...
    4. 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 --...
    5. 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? ----...
  3. #2

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139