PHP: ROT-13

The legendary and super-secret ROT-13 algorithm.

Somewhat useless these days as PHP has included str_rot13() since version 4.2.0, and if you're using an older version than that you should probably consider an upgrade.

<?php

  function rot13 ($str) 
  {

    // characters in the $from string will be replaced by the character in the same
    // place in the $to string (e.g. a will be replaced with n, b with o and so on)
    // rot-13 doesn't touch numbers or special characters so these don't appear here
    $from = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $to   = "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM";
	
    // do the character translation and return the rot-13 encoded string
    return strtr($str, $from, $to);

  }

?>

Questions? Suggestions for improvement? Feel free to get in touch.