note 76975 added to function.str-rot13

From: Date: Wed, 08 Aug 2007 16:01:39 +0000
Subject: note 76975 added to function.str-rot13
Groups: php.notes 
Request: Send a blank email to php-notes+get-129332@lists.php.net to get a copy of this message
This is recursive function to shift the component letters of a string left or right in the ascii table. I've left it simple as it suits my needs, but you may want to include error checking for a null string and also put bounds in place, or make it actually rotate around the whole character set rather than just shifting the string up or down. function asc_shift($string, $amount) { $key = substr($string, 0, 1); if(strlen($string)==1) { return chr(ord($key) + $amount); } else { return chr(ord($key) + $amount) . asc_shift(substr($string, 1, strlen($string)-1), $amount); } } For example: <?php echo asc_shift("TESTING12345@", 5); ?> shifts every character up 5 ascii positions, resulting in this string: YJXYNSL6789:E In reverse: <?php echo asc_shift("YJXYNSL6789:E", -5); ?> shifts every character down 5 ascii positions, resulting in this string: TESTING12345@ ---- Server IP: 194.145.210.4 Probable Submitter: 80.169.172.95 ---- Manual Page -- http://www.php.net/manual/en/function.str-rot13.php Edit -- https://master.php.net/note/edit/76975 Del: integrated -- https://master.php.net/note/delete/76975/integrated Del: useless -- https://master.php.net/note/delete/76975/useless Del: bad code -- https://master.php.net/note/delete/76975/bad+code Del: spam -- https://master.php.net/note/delete/76975/spam Del: non-english -- https://master.php.net/note/delete/76975/non-english Del: in docs -- https://master.php.net/note/delete/76975/in+docs Del: other reasons-- https://master.php.net/note/delete/76975 Reject -- https://master.php.net/note/reject/76975 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#129332) next »