且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何缩短数字串?

更新时间:2023-12-05 11:41:04

.oO(Krakatioison)

我需要一种以较短的形式表达这个数字的方法。一些编码和解码方式将这个数字表示为更短的东西。
例如:000000000040900000可能变成类似:AhD7
所以链接: http://www.newsbackup.com/index.php?...00000040900000
会如下所示: http://www.newsbackup.com/index.php ?n = AhD7




如果n是实数(所以前导零不重要),那么你

可以尝试base_convert:


print base_convert(''000000000040900000'',10,36); //输出:ocmn4

print base_convert(''ocmn4'',36,10); //输出:40900000

http://www.php.net / base_convert


HTH

Micha


base64? (当然没有前导零)


" Michael Fesser" &LT是ne ***** @ gmx.net>在消息中写道

news:gn ******************************** @ 4ax.com ...
.oO(Krakatioison)
我需要一种以较短的形式表达这个数字的方法。一些编码和解码方式将这个数字表示为更短的东西。
例如:000000000040900000可能变成类似:AhD7
所以链接: http://www.newsbackup.com/index.php?...00000040900000
会如下所示: http://www.newsbackup.com/index.php ?n = AhD7



如果n是实数(所以前导零不重要),那么你可以试试base_convert:

print base_convert(''000000000040900000'',10,36); //输出:ocmn4
print base_convert(''ocmn4'',36,10); //输出:40900000

http://www.php.net / base_convert

HTH
Micha



问题是我需要那些前导零。没有

他们就行不通。

Hm ......但是好主意。非常感谢。

还有什么更好的主意吗?哪个永远不会削减我的前导零?


Joe


" Joep" <圣*** @ DeStoep.nl>在消息中写道

news:41 *********************** @ news.xs4all.nl ...
base64? (当然没有前导零)

Michael Fesser &LT是ne ***** @ gmx.net>在消息中写道
新闻:gn ******************************** @ 4ax.com ... .oO(Krakatioison)
我需要一种以较短的形式表达这个数字的方法。一些
编码和解码方式将这个数字表示为更短的东西。
例如:000000000040900000可能变成类似:AhD7
所以链接: http://www.newsbackup.com/index.php?...00000040900000 http://www.newsbackup.com /index.php?n=AhD7



如果n是实数(所以前导零不重要),那么你可以试试base_convert:

print base_convert(''000000000040900000'',10,36); //输出:ocmn4
print base_convert(''ocmn4'',36,10); //输出:40900000

http://www.php.net / base_convert

HTH
Micha




My sites navigation is like this:

http://www.newsbackup.com/index.php?...00000040900000

, depending on the variable "n" (which is always a number), it will take me
anywhere on the site... this number is always changing as I have hundreds of
thousand of pages of text on my site.

Problem:
- in my opinion this just not only look weird, but the variable "n" (number)
is too long.

I need a way to somehow express this number in shorter form. Some encoding
and decoding way to express this number as something shorter.
For example: 000000000040900000 could become something like : AhD7
so the link: http://www.newsbackup.com/index.php?...00000040900000
would look like: http://www.newsbackup.com/index.php?n=AhD7

You know what I mean.

So, I tried to think about it, and I played with the idea to use of gzencode
or gzcompress. Tried it, but these will generate the short code full of
characters out of normal ascii, spaces and so.... I can''t use that, then my
site won''t be search engine friendly.

Please, do you have any suggestions?
Or some short encoding decoding script? Your script can be forever part of
my site.

Joe

.oO(Krakatioison)
I need a way to somehow express this number in shorter form. Some encoding
and decoding way to express this number as something shorter.
For example: 000000000040900000 could become something like : AhD7
so the link: http://www.newsbackup.com/index.php?...00000040900000
would look like: http://www.newsbackup.com/index.php?n=AhD7



If n is a real number (so that leading zeros don''t matter), then you
could try base_convert:

print base_convert(''000000000040900000'', 10, 36); // ouput: ocmn4
print base_convert(''ocmn4'', 36, 10); // output: 40900000

http://www.php.net/base_convert

HTH
Micha


base64? (without the leading zeroes of course)

"Michael Fesser" <ne*****@gmx.net> wrote in message
news:gn********************************@4ax.com...
.oO(Krakatioison)
I need a way to somehow express this number in shorter form. Some encoding
and decoding way to express this number as something shorter.
For example: 000000000040900000 could become something like : AhD7
so the link: http://www.newsbackup.com/index.php?...00000040900000
would look like: http://www.newsbackup.com/index.php?n=AhD7



If n is a real number (so that leading zeros don''t matter), then you
could try base_convert:

print base_convert(''000000000040900000'', 10, 36); // ouput: ocmn4
print base_convert(''ocmn4'', 36, 10); // output: 40900000

http://www.php.net/base_convert

HTH
Micha



Problem is that I need those leading zeros. It will just not work without
them.
Hm... But great Idea. Thanks a lot.
Any better idea? Which would never cut my leading zeros?

Joe


"Joep" <St***@DeStoep.nl> wrote in message
news:41***********************@news.xs4all.nl...
base64? (without the leading zeroes of course)

"Michael Fesser" <ne*****@gmx.net> wrote in message
news:gn********************************@4ax.com...
.oO(Krakatioison)
I need a way to somehow express this number in shorter form. Some
encoding
and decoding way to express this number as something shorter.
For example: 000000000040900000 could become something like : AhD7
so the link: http://www.newsbackup.com/index.php?...00000040900000
would look like: http://www.newsbackup.com/index.php?n=AhD7



If n is a real number (so that leading zeros don''t matter), then you
could try base_convert:

print base_convert(''000000000040900000'', 10, 36); // ouput: ocmn4
print base_convert(''ocmn4'', 36, 10); // output: 40900000

http://www.php.net/base_convert

HTH
Micha