Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Very simple Encode/Decode string

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?

like image 906
Alex Avatar asked Mar 20 '26 19:03

Alex


1 Answers

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

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

You can also do type casting with settype().

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().

like image 150
pr1001 Avatar answered Mar 23 '26 07:03

pr1001



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!