Looking for 64-bit URL encoding, I found this to be a very non-standard thing. Despite the abundance of built-in functions that PHP has, there is no URL for encoding with encoding. On the base64_encode() page for base64_encode() most comments suggest using this function wrapped in strtr() :
function base64_url_encode($input) { return strtr(base64_encode($input), '+/=', '-_,'); }
The only Perl module I could find in this area is MIME :: Base64 :: URLSafe ( source ), which performs an internal replacement:
sub encode ($) { my $data = encode_base64($_[0], ''); $data =~ tr|+/=|\-_|d; return $data; }
Unlike the PHP function above, this version of Perl completely discards the '=' (equals) character, rather than replacing it with a ',' (comma), as PHP does. Equals is a complementary symbol, so the Perl module replaces them as needed when decoding, but this difference makes these two implementations incompatible.
Finally, the Python function urlsafe_b64encode (s) supports the addition of '=', prompting someone to put this function in order to remove the indentation that appears noticeably in the Google results for 'python base64 url safe' :
from base64 import urlsafe_b64encode, urlsafe_b64decode def uri_b64encode(s): return urlsafe_b64encode(s).strip('=') def uri_b64decode(s): return urlsafe_b64decode(s + '=' * (4 - len(s) % 4))
The desire here is to have a string that can be included in the URL without further encoding, hence the groove or translation of the characters "+", "/" and "=". Since there is no specific standard , what is the right way?
url php encoding perl base64
Drew stephens
source share