note 96304 added to function.base-convert

From: Date: Fri, 19 Feb 2010 15:55:16 +0000
Subject: note 96304 added to function.base-convert
Groups: php.notes 
Request: Send a blank email to php-notes+get-166177@lists.php.net to get a copy of this message
Another pair of functions to convert between numbers and their uppercase alphabet representation (A, B, ..., Z, AA, AB, ..., AZ, BA, BB, ..., BZ, CA, ..., ZZ, AAA, AAB, etc.) <?php /* * Convert an integer to a string of uppercase letters (A-Z, AA-ZZ, AAA-ZZZ, etc.) */ function num2alpha($n) { for($r = ""; $n >= 0; $n = intval($n / 26) - 1) $r = chr($n%26 + 0x41) . $r; return $r; } /* * Convert a string of uppercase letters to an integer. */ function alpha2num($a) { $l = strlen($a); $n = 0; for($i = 0; $i < $l; $i++) $n = $n*26 + ord($a[$i]) - 0x40; return $n-1; } ?> ---- Server IP: 192.41.40.227 Probable Submitter: 66.155.211.158 ---- Manual Page -- http://www.php.net/manual/en/function.base-convert.php Edit -- https://master.php.net/note/edit/96304 Del: integrated -- https://master.php.net/note/delete/96304/integrated Del: useless -- https://master.php.net/note/delete/96304/useless Del: bad code -- https://master.php.net/note/delete/96304/bad+code Del: spam -- https://master.php.net/note/delete/96304/spam Del: non-english -- https://master.php.net/note/delete/96304/non-english Del: in docs -- https://master.php.net/note/delete/96304/in+docs Del: other reasons-- https://master.php.net/note/delete/96304 Reject -- https://master.php.net/note/reject/96304 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#166177) next »