Difference between revisions of "RemoveHTMLTags"

From Second Life Wiki
Jump to navigation Jump to search
m (<lsl> tag to <source>)
 
(4 intermediate revisions by 3 users not shown)
Line 7: Line 7:
|func_footnote=
|func_footnote=
See also: [[String]]
See also: [[String]]
|spec=<lsl>
|spec=<source lang="lsl2">
string RemoveHTMLTags(string src)
string remove_HTML_tags(string source)
{
{
     integer is_HTML = 0;
     integer is_HTML = FALSE;
     string result = "";
 
     string s;
     string output;
     integer i;
     string characterInSource;
     for (i=0; i<llStringLength(src); i++)
 
     integer index;
     do
     {
     {
      s = llGetSubString(src,i,i);  
        characterInSource = llGetSubString(source, index, index);
      if (s == "<")
 
      {
        if (characterInSource == "<")
             is_HTML = 1;
//      {
      }
             is_HTML = TRUE;
      if (is_HTML == 0 && s != "\n")
//      }
        {
 
             result += s;  
        if (!is_HTML && characterInSource != "\n")
        }
//      {
      if (s == ">")
             output += characterInSource;
        {
//      }
             is_HTML = 0;
 
        }
        if (characterInSource == ">")
//      {
             is_HTML = FALSE;
//      }
     }
     }
     return result;
    while (++index < llStringLength(source));
 
     return
        output;
}
}
</lsl>
</source>


|caveats=none
|caveats=
|examples=<lsl>
*Text in elements that are not normally rendered will show up in the output (inline script tags, etc).
|examples=<source lang="lsl2">
src = RemoveHTMLTags(src);
src = RemoveHTMLTags(src);
</lsl>
</source>
|helpers
|helpers
|notes
|notes

Latest revision as of 15:34, 22 January 2015

Summary

Function: string RemoveHTMLTags( string input_string );

Returns a string with HTML ( or XML ) tags and newline characters removed.

• string input_string String to remove HTML tags from

See also: String

Specification

string remove_HTML_tags(string source)
{
    integer is_HTML = FALSE;

    string output;
    string characterInSource;

    integer index;
    do
    {
        characterInSource = llGetSubString(source, index, index);

        if (characterInSource == "<")
//      {
            is_HTML = TRUE;
//      }

        if (!is_HTML && characterInSource != "\n")
//      {
            output += characterInSource;
//      }

        if (characterInSource == ">")
//      {
            is_HTML = FALSE;
//      }
    }
    while (++index < llStringLength(source));

    return
        output;
}

Caveats

  • Text in elements that are not normally rendered will show up in the output (inline script tags, etc).

Examples

src = RemoveHTMLTags(src);