Rot 13

17 Ⅴ 2010

Basic rot13 function for PHP (remember that this is NOT secure encryption!).
Itís built into php nowadays, but if you have an old version you may not.

// Rot 13 function for older php versions
function rot13($text){
	$length = strlen($text);
	$newtext = '';
	 for($i = 0; $i < $length; $i++){
		 $index = ord($text[$i]);
		 // Rotate upper case.
		 if($index > 64 && $index < 91){
			 $index += 13;
			 if($index > 90) $index -= 26;
			 $newtext .= chr($index);
		// Rotate lower case.
		}elseif($index > 96 && $index < 123){
			$index += 13;
			if($index > 122) $index -= 26;
			$newtext .= chr($index);
		 }else{ $newtext .= $text[$i]; }
	 }
	 return $newtext;
}