note 119327 added to function.base64-encode

From: Date: Fri, 13 May 2016 14:31:08 +0000
Subject: note 119327 added to function.base64-encode
Groups: php.notes 
Request: Send a blank email to php-notes+get-205480@lists.php.net to get a copy of this message
@gutzmer at usa dot net Nice idea! However... The function base64url_decode doesn't pad strings longer than 4 chars. str_pad will only pad the string if the second argument is larger than the length of the original string. So the correct function should be: <?php function base64url_decode($data) { $len = strlen($data); return base64_decode(str_pad(strtr($data, '-_', '+/'), $len + $len % 4, '=', STR_PAD_RIGHT)); } Note that base64_decode works fine without the padding, that is why your function works. ---- Server IP: 72.52.91.14 Probable Submitter: 195.1.207.220 ---- Manual Page -- http://php.net/manual/en/function.base64-encode.php Edit -- https://master.php.net/note/edit/119327 Del: integrated -- https://master.php.net/note/delete/119327/integrated Del: useless -- https://master.php.net/note/delete/119327/useless Del: bad code -- https://master.php.net/note/delete/119327/bad+code Del: spam -- https://master.php.net/note/delete/119327/spam Del: non-english -- https://master.php.net/note/delete/119327/non-english Del: in docs -- https://master.php.net/note/delete/119327/in+docs Del: other reasons-- https://master.php.net/note/delete/119327 Reject -- https://master.php.net/note/reject/119327 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#205480) next »