Welcome Forums Aliases nohtml – Remove HTML characters from a string

This topic contains 0 replies, has 1 voice, and was last updated by  bleepy 3 years, 4 months ago.

  • Author
    Posts
  • #441

    bleepy
    Keymaster

    Description:
    Removes HTML entities from strings, mainly for usage in socket scripts.

    Usage:
    $nohtml(string)

    Example:
    $nohtml(<h1>Heading</h1><p>I like turtles</p>)

    Code:

    alias nohtml {
      var %x, %i = $regsub($1-,/< [^>]+(?:>|$)|^[^<>]+>/g,$chr(32),%x), %a = 1
      while ($regex(*,%x,/(&#(\d+?);)/)) { if ($regml(*,1).pos < %a) { goto more } | %x = $replace(%x,$regml(*,1),$chr($regml(*,2))) | inc %a }
      :more
      %x = $replacecs(%x,°,°,Í,í,º,º,§,§,Î,î,Ù,ù,<,<,´,´,>,>,¬,¬,Á,á,Õ,õ,Ç,ç,ª,ª,Ô,ô,Ó,ó,Ý,ý,µ,µ,Å,å,÷,÷,Ë,ë,¡,¡,Ã,ã,Ì,ì,&,&,³,³,­,­,®,®,¾,¾,ÿ,ÿ,À,à,¿,¿,Ê,ê,£,£,Ø,ø,©,©)
      %x = $replacecs(%x,»,»,·,·,Ü,ü,±,±,²,²,¼,¼,×,×,Ï,ï,¥,¥,¶,¶,È,è,Ð,ð,¨,¨, ,$chr(160),¯,¯,ß,ß,¸,¸,¤,¤,Ö,ö,Ú,ú,¦,¦,",",Þ,þ,«,«,Ä,ä,Ò,ò,¢,¢,É,é,¹,¹,Æ,æ,Â,â,½,½,Û,û,Ñ,ñ)
      return %x
    }
    • This topic was modified 3 years, 4 months ago by  bleepy.
    • This topic was modified 3 years, 4 months ago by  bleepy.

The forum ‘Aliases’ is closed to new topics and replies.