Encode Forward Slash with &#x2F in Text area drupal 7 form
You can use something like the following to convert all characters you want to convert into their corresponding HTML entity version. I have added a check on converting only non alpha-numeric characters into HTML entities. You can add a different logic to convert only those characters you want to convert (in the if condition with ctype_alum)

The following is adapted from the answer here

function encode($str) {
  $str = mb_convert_encoding($str , 'UTF-32', 'UTF-8'); //big endian
  $split = str_split($str, 4);

  $res = "";
  $pos = 0;
  foreach ($split as $c) {
    // Check if the character is alpha numeric and
    // if not, convert to HTML entity.
    if (!ctype_alnum ($str[$pos])) {
      $cur = 0;
      for ($i = 0; $i &lt; 4; $i++) {
        $cur |= ord($c[$i]) &lt;&lt; (8*(3 - $i));
      }
      $res .= "&amp;#" . $cur . ";";
    }
    else {
      $res .= $str[$pos];
    }
    $pos++;
  }
  return $res;
}