note 107049 added to function.chr

From: Date: Tue, 03 Jan 2012 10:08:04 +0000
Subject: note 107049 added to function.chr
Groups: php.notes 
Request: Send a blank email to php-notes+get-185269@lists.php.net to get a copy of this message
Converting numbers to chars (debugged) and vice versa: if(is_numeric($input)){ $output = numToChars($input); } else{ $output = charsToNum($input); } function numToChars($num, $start = 65, $end = 90){ $num = abs($num); $str = ''; $range = $end - $start + 1; while($num != 0){ $char = $num % $range; if($char === 0) $char = $range; $str = chr( $char + $start - 1) . $str; $num = ($num - $char) / $range; } return $str; } function charsToNum($str, $start = 65, $end = 90){ $str = strtoupper($str); $num = 0; $range = $end - $start + 1; $strlen = strlen($str); for($i = 0; $i < $strlen; $i++){ $c = substr($str, $i, 1); $ord = ord($c); if($ord >= $start && $ord <= $end){ $numbef = $num; $num += ($ord - $start + 1) * pow($range, ($strlen-1 - $i)); } } return $num; } ---- Server IP: 212.124.37.9 Probable Submitter: 212.204.125.106 ---- Manual Page -- http://www.php.net/manual/en/function.chr.php Edit -- https://master.php.net/note/edit/107049 Del: integrated -- https://master.php.net/note/delete/107049/integrated Del: useless -- https://master.php.net/note/delete/107049/useless Del: bad code -- https://master.php.net/note/delete/107049/bad+code Del: spam -- https://master.php.net/note/delete/107049/spam Del: non-english -- https://master.php.net/note/delete/107049/non-english Del: in docs -- https://master.php.net/note/delete/107049/in+docs Del: other reasons-- https://master.php.net/note/delete/107049 Reject -- https://master.php.net/note/reject/107049 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#185269) next »