$htmlspecialchars()
Posted by rannmann
Thursday, October 18, 2007
Description: Convert text into it's HTML character equivilent

alias htmlspecialchars {
  var %count = 1,%newstring
  while (%count <= $len($1-)) {
    var %char = $mid($1-,%count,1)
    if (%char != $chr(32)) && (%char !isnum) && (%char !isalpha) && (%char != $chr(45)) { %newstring = $+(%newstring,%,$base($asc(%char),10,16)) }

    ; throw in anything you deem appropriate here (some websites require _ instead of %20 for space, etc.  Example below.
    ; elseif (%char == $chr(32)) { %newstring = $+(%newstring,_) }

    else { %newstring = $+(%newstring,%char) }
    inc %count
  }
  return %newstring
}
Submit a comment
Oops! You need to login or register before you can post a comment!

ebaum's world