PHP 编码字符串加上当前日期

发布于 2024-12-25 14:55:10 字数 177 浏览 2 评论 0原文

我不知道如何在有点短的乱码结果中对字符串+当前时间进行编码...类似:

$random = base64_encode($_POST['phone']);

将日期附加到也已编码的电话变量中,当我执行上述操作时,它会出现长乱码混乱,我希望它短一些。有没有办法做到我所缺少的?

I can't figure out how to encode a string + current hour in a somewhat shortish garbled result... something like:

$random = base64_encode($_POST['phone']);

with a date appended to the phone var that's also encoded, when I do the above it comes out to a long garbled mess, I'd like it to be somewhat shorter. Is there a way to do this that I'm missing ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还如梦归 2025-01-01 14:55:11

我会从字面上回答你的问题,因为我无法深入了解你的实际用例或你的真正目标是什么。


我不知道如何编码字符串+当前时间

$string = base64_encode('some string' . date('H'));

类似于:$random = base64_encode($_POST['phone']);,并将日期附加到也已编码的电话变量

$string = base64_encode($_POST['phone'] . base64_encode(date('H')));

当我执行上述操作时,结果会出现一长串乱码,我希望它能短一些。有没有一种方法可以做到我所缺少的?

$my_string_length = 100;
$string = substr($string, 0, $my_string_length);

请记住,这并不是真正的随机字符串,并且您将把数据编码成一种形式,以防止您将两个单独的数据分开。

I'll answer your question literally, since I can't get any insight into your actual use case or what your real goals are.


I can't figure out how to encode a string + current hour

$string = base64_encode('some string' . date('H'));

something like: $random = base64_encode($_POST['phone']); with a date appended to the phone var that's also encoded

$string = base64_encode($_POST['phone'] . base64_encode(date('H')));

when I do the above it comes out to a long garbled mess, I'd like it to be somewhat shorter. Is there a way to do this that I'm missing ?

$my_string_length = 100;
$string = substr($string, 0, $my_string_length);

Just keep in mind that this is not truly a random string, and that you'll be encoding your data into a form that will prevent you from picking apart the two separate pieces of data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文