PDA

View Full Version : Detect HTML


cbk1994
11-29-2007, 04:54 AM
I made this quickly for my message system that used GUIs.

I'll probably eventually make it simply remove the HTML, but for now it's a way to tell if they inputted HTML.

An example is if you have a GUI message system, and someone massed <img src="block.png"> for example. You could disable HTML, but then if you needed colors, etc, you couldn't use them.

The way I used it was this:

if ( player.chat.starts( ":mass" ) )
{
temp.txt = player.chat.substring( 5 ).trim();
temp.h = removeHTML( temp.txt );
triggerserver( "gui", name, "massMessage", temp.h );
}


Here is the class.

Script for class functions_removehtml:
public function removeHTML( text )
{
this.html = { "a", "b", "body", "br", "center", "font", "hl", "hr", "i", "ignorelinebreaks", "img", "p", "spam", "ul", "ol", "li", "div" };

for ( temp.a : this.html )
{
temp.n = "<" @ temp.a;
if ( text.pos( @ temp.n ) > -1 )
{
temp.p = ( text.pos( @ temp.n ) );
text = text.substring( 0, temp.p ) @ text.substring( temp.p + 1 );
}
temp.n = "</" @ temp.a;
if ( text.pos( @ temp.n ) > -1 )
{
temp.p = ( text.pos( @ temp.n ) );
text = text.substring( 0, temp.p ) @ text.substring( temp.p + 1 );
}
}
return text;
}
//#CLIENTSIDE
public function removeHTML( text )
{
this.html = { "a", "b", "body", "br", "center", "font", "hl", "hr", "i", "ignorelinebreaks", "img", "p", "spam", "ul", "ol", "li", "div" };

for ( temp.a : this.html )
{
temp.n = "<" @ temp.a;
if ( text.pos( @ temp.n ) > -1 )
{
temp.p = ( text.pos( @ temp.n ) );
text = text.substring( 0, temp.p ) @ text.substring( temp.p + 1 );
}
temp.n = "</" @ temp.a;
if ( text.pos( @ temp.n ) > -1 )
{
temp.p = ( text.pos( @ temp.n ) );
text = text.substring( 0, temp.p ) @ text.substring( temp.p + 1 );
}
}
return text;
}


It's a very simple script, but I figured someone might get some use out of it. When I make it remove HTML, I will update it.

Feel free to leave feedback!
Thanks,
Chris Zakuto

EDIT: Updated it to remove the HTML instead of just giving an error. It removes the < right before it, making it not work. There was also another error that I fixed.

Tolnaftate2004
11-29-2007, 05:31 AM
<<b>Avoided!<</b>

Also, "spam"? span, perhaps.
e: What is "hl"?

cbk1994
11-29-2007, 01:41 PM
<<b>Avoided!<</b>

Also, "spam"? span, perhaps.
e: What is "hl"?

hl is horizontal line.

Looks like I made a typo. And an error.

I'll fix those after school today and repost! Thank you for the feedback!

xAndrewx
11-05-2011, 10:11 AM
Thanks! Needed this :)

cbk1994
11-05-2011, 09:38 PM
Thanks! Needed this :)

Not sure what you're using it for but couldn't you just replace every instance of > with &gt;? That's what I usually do in places where HTML shouldn't be allowed.

Also, I'm pretty sure this script has some big holes in it. I wrote it many years ago.

xAndrewx
11-06-2011, 11:48 AM
hehe I noticed some errors, but I modified it ^^

Good idea with the '>'- I'll do that =D Thanks