Mega Code Archive

 
Categories / Delphi / LAN Web TCP
 

Removing all HTML tags from a string

Title: Removing all HTML tags from a string. Question: I was developing a web application, where I received strings from a HTML form. There was a problem: if the user entered any HTML tags, the resulting web page could be not what I wanted it to be. I had no time and lust to put an array of all HTML tags in my application... so I tryed to do that only seeking for ""... it works! Answer: That's the simply solution to the problem presented: Function RemoveHTMLTags( FromWhere : String ) : String; Var IdX : Integer; IdY : Integer; ForceExit : Boolean; Begin Result := FromWhere; ForceExit := False; Repeat IdX := Pos( ' IdY := Pos( '', Result ); If ( ( IdX 0 ) And ( IdY IdX ) ) Then Begin Result := Copy( Result, 1, ( IdX - 1 ) ) + Copy( Result, ( IdY + 1 ), MaxInt ); End Else Begin ForceExit := True; End; Until ( ( IdX = 0 ) Or ( IdY = 0 ) Or ( ForceExit ) ); End; Other solutions are wellcome!