note 76355 added to function.str-rot13
| From: | arwab at surrealwebs dot com | Date: | Wed, 11 Jul 2007 20:11:48 +0000 |
| Subject: | note 76355 added to function.str-rot13 | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-128390@lists.php.net to get a copy of this message | ||
here's my rot function, it works anyway
<?php
/**
* preforms the rotation algorithm on the passed in string
*/
function _rot( $str , $dist=13 ){
if( !is_numeric($dist) || $dist < 0){
$dist = 13;
}
$u_lower = 65; $u_upper = 90;
$l_lower = 97; $l_upper = 122;
$char_count = ($u_upper - $u_lower) +1;
while( $dist > $char_count ){
$dist -= $char_count;
}
$newstr = '';
for( $i=0; $i<strlen($str); ++$i){
$c = ord($str[$i]);
/*
* Check if the character is within the bounds of our function (a-zA-z)
* if not it gets tacked on to the string as is and we move on to the
* next one.
*/
if( $c<$u_lower || $c>$l_upper || ( $c>$u_upper && $c <$l_lower ) ){
$newstr .= chr($c);
continue;
}
$lower = ( $c<=$u_upper?$u_lower:$l_lower);
$upper = ( $c<=$u_upper?$u_upper:$l_upper);
$c += $dist;
if( $c > $upper){
$c = (($c - $upper) + ($lower-1));
}
$newstr .= chr($c);
}
return $newstr;
}
?>
----
Server IP: 64.71.164.2
Probable Submitter: 216.153.253.10
----
Manual Page -- http://www.php.net/manual/en/function.str-rot13.php
Edit -- https://master.php.net/note/edit/76355
Del: integrated -- https://master.php.net/note/delete/76355/integrated
Del: useless -- https://master.php.net/note/delete/76355/useless
Del: bad code -- https://master.php.net/note/delete/76355/bad+code
Del: spam -- https://master.php.net/note/delete/76355/spam
Del: non-english -- https://master.php.net/note/delete/76355/non-english
Del: in docs -- https://master.php.net/note/delete/76355/in+docs
Del: other reasons-- https://master.php.net/note/delete/76355
Reject -- https://master.php.net/note/reject/76355
Search -- https://master.php.net/manage/user-notes.php