Thread: Detect HTML
View Single Post
  #1  
Old 11-29-2007, 04:54 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Detect HTML

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:
PHP Code:
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:
PHP Code:
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.
__________________

Last edited by cbk1994; 11-29-2007 at 05:04 AM..
Reply With Quote