note 47725 deleted from function.str-rot13 by nlopess
| From: | nlopess@php.net | Date: | Fri, 17 Mar 2006 17:32:57 +0000 |
| Subject: | note 47725 deleted from function.str-rot13 by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-105995@lists.php.net to get a copy of this message | ||
Note Submitter: joh at n dot liesen dot se
----
It's also possible to rot13 a string without using a lookup table.
<?php
function rot13($s)
{
$rot13 = "";
for ($i = 0; $i < strlen($s); ++$i)
{
$char = ord($s{$i});
$cap = $char & 32;
$char &= ~$cap;
$char = (($char >= ord('A')) && ($char <= ord('z'))) ?
(($char - ord('A') + 13) % 26 + ord('A')) : $char;
$char |= $cap;
$rot13 .= chr($char);
}
return $rot13;
}
?>