PHP:非常简单的Encode / Decode字符串 [英] PHP: Very simple Encode/Decode string

查看:168
本文介绍了PHP:非常简单的Encode / Decode字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何PHP函数将字符串编码为int值,稍后我可以将其解码回没有任何键的字符串?

Is there any PHP function that encodes a string to a int value, which later I can decode it back to a string without any key?

推荐答案

当然,你可以将字符串转换为数字,反之亦然。考虑:

Sure, you can convert strings to numbers and vice versa. Consider:

$a = "" + 1
gettype($a) // integer
$b = "$a"
gettype($b) // string

你也可以使用<输入 a href =http://www.php.net/manual/en/function.settype.php =noreferrer> settype()。

You can also do type casting with settype().

如果我误解了您并想要编码任意字符串,请考虑使用 base64_encode() bas64_decode()。如果要将基本64字符串表示转换为基数为10的整数,只需使用 base_convert ()

If I misunderstood you and you want to encode arbitrary strings, consider using base64_encode() and bas64_decode(). If you want to convert the base 64 string representation to a base 10 integer, simply use base_convert().

这篇关于PHP:非常简单的Encode / Decode字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆