note 74086 added to language.operators.increment

From: Date: Fri, 23 Mar 2007 17:19:11 +0000
Subject: note 74086 added to language.operators.increment
Groups: php.notes 
Request: Send a blank email to php-notes+get-124752@lists.php.net to get a copy of this message
this can probably be more easilly done with case examples but i had a case where i needed to come up with the ability to add an turn 11 digits into a field where only 10 would fit (database restrictions) so had to convert the basic numrical into a more unique feature this will go the normal 0-9 then a-z, then A-Z (so the first 10 turned into 62 possibilities) using this function, a 1 digit database field now can hold 62 records, isntead of 10 a 2 digit database field now can hold 3843 records a 3 digit field can now hold... im sure you see its exponental <? $number = '1zZorl4'; // starting number $newnum = incremental($number); echo $number; echo "<br />"; echo $newnum; // this just to show that its working function incremental($number) { $number = str_pad($number, 10, '0', STR_PAD_LEFT); // adds leading zeros $ones = substr($number, 9, 1); $tens = substr($number, 8, 1); $hund = substr($number, 7, 1); $thou = substr($number, 6, 1); $ttho = substr($number, 5, 1); $htho = substr($number, 4, 1); $mils = substr($number, 3, 1); $tmil = substr($number, 2, 1); $hmil = substr($number, 1, 1); $bils = substr($number, 0, 1); // breaks down to placement if ($ones == '9') { $ones = 'a'; } else if ($ones == 'z') { $ones = 'A'; } else if ($ones == 'Z') { $ones = '0'; if ($tens == '9') { $tens = 'a'; } else if ($tens == 'z') { $tens = 'A'; } else if ($tens == 'Z') { $tens = '0'; if ($hund == '9') { $hund = 'a'; } else if ($hund == 'z') { $hund = 'A'; } else if ($hund == 'Z') { $hund = '0'; if ($thou == '9') { $thou = 'a'; } else if ($thou == 'z') { $thou = 'A'; } else if ($thou == 'Z') { $thou = '0'; if ($ttho == '9') { $ttho = 'a'; } else if ($ttho == 'z') { $ttho = 'A'; } else if ($ttho == 'Z') { $ttho = '0'; if ($htho == '9') { $htho = 'a'; } else if ($htho == 'z') { $htho = 'A'; } else if ($ttho == 'Z') { $ttho = '0'; if ($mils == '9') { $mils = 'a'; } else if ($mils == 'z') { $mils = 'A'; } else if ($mils == 'Z') { $mils = '0'; if ($tmil == '9') { $tmil = 'a'; } else if ($tmil == 'z') { $tmil = 'A'; } else if ($tmil == 'Z') { $tmil = '0'; if ($hmil == '9') { $hmil = 'a'; } else if ($hmil == 'z') { $hmil = 'A'; } else if ($hmil == 'Z') { $hmil = '0'; if ($bils == '9') { $bils = 'a'; } else if ($bils == 'z') { $bils = 'A'; } else { $bils++; } } else { $hmil++; } } else { $tmil++; } } else { $mils++; } } else { $htho++; } } else { $ttho++; } } else { $thou++; } } else { $hund++; } } else { $tens++; } } else { $ones++; } $number = $bils . $hmil . $tmil . $mils . $htho . $ttho . $thou . $hund . $tens . $ones; $number = ltrim($number, '0'); // remove padding return $number; } ?> ---- Server IP: 64.71.164.2 Probable Submitter: 12.219.196.135 ---- Manual Page -- http://www.php.net/manual/en/language.operators.increment.php Edit -- https://master.php.net/note/edit/74086 Del: integrated -- https://master.php.net/note/delete/74086/integrated Del: useless -- https://master.php.net/note/delete/74086/useless Del: bad code -- https://master.php.net/note/delete/74086/bad+code Del: spam -- https://master.php.net/note/delete/74086/spam Del: non-english -- https://master.php.net/note/delete/74086/non-english Del: in docs -- https://master.php.net/note/delete/74086/in+docs Del: other reasons-- https://master.php.net/note/delete/74086 Reject -- https://master.php.net/note/reject/74086 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#124752) next »