以数值方式增加 alpha 值
就像标题所暗示的那样,我需要做类似的事情......
$i++;//we all know this.
$value = 'a';
increment($value);// i need this functionality
//output
string [ b ]
///here are some more samples, to help you understand...
increment('b'); //output// c
increment('z'); //output// A [capital A not fussy but would be good :) ]
increment('9'); //output// a1
increment('a1'); //output// a2
increment('aa1'); //output// aa2
等等...... 更新
好吧,假设我使用数值
$id++;
我最终会得到一个巨大的数字1310743942525
;
这可能比“ab34c9”占用更多的空间,我试图保存字符长度以保存在数据库上......
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您尝试将其视为 62 基数:
http://www.pgregg.com/projects/php/base_conversion/base_conversion.php
源代码位于
http://www.pgregg.com/projects/php/base_conversion/base_conversion.inc.phps
将其转换为十进制,递增,然后将其转换回基数 62
更新< /strong>
从我阅读代码的方式来看,您可以拥有这样的工作流程:
You try to treat it as a base 62 number:
http://www.pgregg.com/projects/php/base_conversion/base_conversion.php
with source code at
http://www.pgregg.com/projects/php/base_conversion/base_conversion.inc.phps
convert it to decimal, increment, and convert it back to base 62
UPDATE
From how I read the code, you could have a workflow like this:
如果您只想节省数据库空间,请考虑这一点。
在 MySQL 中,您可以拥有一个类型为
UNSIGNED BIGINT
的字段。该字段的最大大小为18446744073709551615,存储空间只有8个字节。如果您要将此数字 (1.844 x 10^19) 转换为 base-62,它将表示为
LygHa16AHYF
。您需要一个CHAR(11)
(11 字节)或一个VARCHAR(11)
(12 字节)来存储转换后的数字。如果您使用 VARCHAR 作为字段类型,则较小的数字将占用较少的空间,但对于较大的数字,实际上会占用更多空间。无论如何,8 个字节对于一个巨大的数字来说是相当小的。我会节省精力,只需将 DB 字段设为
UNSIGNED BIGINT
即可。If all you are trying to do is save database space, consider this.
In MySQL you can have a field with a type
UNSIGNED BIGINT
. The maximum size of this field is 18446744073709551615 and the storage space is only 8 bytes.If you were to convert this number (1.844 x 10^19) to base-62, it would be represented as
LygHa16AHYF
. You would need aCHAR(11)
(11 bytes) or aVARCHAR(11)
(12 bytes) in order to store the converted number.If you used VARCHAR for the field type, smaller numbers would take less space, but for the larger numbers it actually takes more. 8 bytes for a huge number is pretty minimal anyway. I would save the effort and just make the DB field a
UNSIGNED BIGINT
.您可以使用每个字母的 ascii 代码。这只是一个向您展示想法的简单示例,当然,如果您想将 'aa1' 增加到 'aa2',则需要进行大量修改,但不可能;P 您只需要编写几个条件即可。
http://www.asciitable.com/ - ASCII 代码表 :)
You can use ascii codes of each letter. This is just a simple example that will show you the idea, ofcourse it need a lot of modyfications if you want to increment 'aa1' into 'aa2' but impossible is nothig ;P You will just need to write few conditions.
http://www.asciitable.com/ - ASCII codes table :)