note 93759 added to function.str-rot13

From: Date: Sat, 26 Sep 2009 15:54:23 +0000
Subject: note 93759 added to function.str-rot13
Groups: php.notes 
Request: Send a blank email to php-notes+get-161097@lists.php.net to get a copy of this message
Here's my implementation of a str_rot that takes a custom offset. It's faster than the others here because it allocates the output string in one go instead of tacking on characters one at a time. It can handle positive or negative offsets of any size, and it fixes everything up to ensure only upper and lower case letters are translated and that they wrap around correctly within the alphabet. function str_rot($s, $n = 13) { $n = (int)$n % 26; if (!$n) return $s; for ($i = 0, $l = strlen($s); $i < $l; $i++) { $c = ord($s[$i]); if ($c >= 97 && $c <= 122) { $s[$i] = chr(($c - 71 + $n) % 26 + 97); } else if ($c >= 65 && $c <= 90) { $s[$i] = chr(($c - 39 + $n) % 26 + 65); } } return $s; } ---- Server IP: 89.185.144.38 Probable Submitter: 89.100.69.76 ---- Manual Page -- http://www.php.net/manual/en/function.str-rot13.php Edit -- https://master.php.net/note/edit/93759 Del: integrated -- https://master.php.net/note/delete/93759/integrated Del: useless -- https://master.php.net/note/delete/93759/useless Del: bad code -- https://master.php.net/note/delete/93759/bad+code Del: spam -- https://master.php.net/note/delete/93759/spam Del: non-english -- https://master.php.net/note/delete/93759/non-english Del: in docs -- https://master.php.net/note/delete/93759/in+docs Del: other reasons-- https://master.php.net/note/delete/93759 Reject -- https://master.php.net/note/reject/93759 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#161097) next »