$htmlfree
Posted by Fubar
Friday, October 22, 2004
Description: Takes off HTML coding and also changes a few things

This doesn't come with the entities.ini but the format of the entities.ini should be:
[entities]
lt=<
gt=>

and so forth
here's the code
alias htmlfree {
  var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $replace(%x,  ,$chr(32))
  var %i = $pos(%x,&,1)
  while (%i) {
    var %entity = $gettok($mid(%x,$calc(%i +1)),1,59)
    var %char
    if ($left(%entity,2) == #x) {
      set %char $chr($base($right(%entity,-2),16,10))
    }
    elseif ($left(%entity,1) == $eval(#,0)) {
      set %char $chr($right(%entity,-1))
    }
    else {
      set %char $readini(entities.ini,entities,%entity)
    }
    if (%char != $null) {
      set %x $+($left(%x,$calc(%i -1)),%char,$mid(%x,$calc(%i + $len(%entity) +2)))
    }
    inc %i
    set %j $pos($mid(%x,%i),&,1)
    if (!%j) { break }
    set %i $calc(%i + %j -1)
  }
  if (st $+ $chr(41) $+ $chr(32) isin %x) {
    var %x $remove(%x,st $+ $chr(41) $+ $chr(32)
    return %x
    halt
  }
  return %x
}

this changes the &##; to their respective characters.
Submit a comment
Oops! You need to login or register before you can post a comment!

ebaum's world