note 48220 added to function.chr

From: Date: Wed, 15 Dec 2004 18:04:54 +0000
Subject: note 48220 added to function.chr
Groups: php.notes 
Request: Send a blank email to php-notes+get-81824@lists.php.net to get a copy of this message
Same function as suggested by tippy2k/jmartin. tippy2k's code seems to have a syntax error in the function declaration; jmartin's code throws a notice. So here's yet another version, without temporary variables and loops: <? // 1 <= $a <= 702 function col2str($a) { return ($a-->26?chr(($a/26+25)%26+ord('A')):'').chr($a%26+ord('A')); } // Example $colname = col2str(1) // returns "A" $colname = col2str(27) // returns "AA" $colname = col2str(702) // returns "ZZ" ?> ---- Manual Page -- http://www.php.net/manual/en/function.chr.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+48220 Delete -- http://master.php.net/manage/user-notes.php?action=delete+48220&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48220&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48220&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48220&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48220&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48220&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+48220&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#81824) next »