note 74780 added to function.chr

From: Date: Fri, 27 Apr 2007 09:02:07 +0000
Subject: note 74780 added to function.chr
Groups: php.notes 
Request: Send a blank email to php-notes+get-125909@lists.php.net to get a copy of this message
I'm sorry to say that the posted convertIntToAlphabet function does not work correctly. It fails on numbers with a "Z" in it! Aside that it also gives a PHP warning, I really did not like recursion 'cauz huge numbers leads into unneeded memory usage. Here some results showing problems: Dec convertIntToAlphabet ... 24 X 25 Y 26 -> empty! 27 AA 28 AB ... 76 BX 77 BY 78 -> empty! 79 CA 80 CB ... 1350 AYX 1351 AYY 1352 -> empty! 1353 A -> bad! 1354 B -> bad! So I have written another version: function toAlphaNumber( $num ) { $anum = ''; while( $num >= 1 ) { $num = $num - 1; $anum = chr(($num % 26)+65).$anum; $num = $num / 26; } return $anum; } With improved results: Dec toAlphaNumber ... 24 X 25 Y 26 Z 27 AA 28 AB ... 76 BX 77 BY 78 BZ 79 CA 80 CB ... 1350 AYX 1351 AYY 1352 AYZ 1353 AZA 1354 AZB ---- Server IP: 83.137.20.120 Probable Submitter: 212.238.158.23 ---- Manual Page -- http://www.php.net/manual/en/function.chr.php Edit -- https://master.php.net/note/edit/74780 Del: integrated -- https://master.php.net/note/delete/74780/integrated Del: useless -- https://master.php.net/note/delete/74780/useless Del: bad code -- https://master.php.net/note/delete/74780/bad+code Del: spam -- https://master.php.net/note/delete/74780/spam Del: non-english -- https://master.php.net/note/delete/74780/non-english Del: in docs -- https://master.php.net/note/delete/74780/in+docs Del: other reasons-- https://master.php.net/note/delete/74780 Reject -- https://master.php.net/note/reject/74780 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#125909) next »