note 129979 added to function.base64-encode

From: Date: Wed, 15 Jan 2025 16:59:38 +0000
Subject: note 129979 added to function.base64-encode
Groups: php.notes 
Request: Send a blank email to php-notes+get-221794@lists.php.net to get a copy of this message
In lieu with biziclop answer here a small upgrade. <?php /** * convert bin to url friendly base64 */ function base64url_encode( string $data ): string { return rtrim( strtr( base64_encode( $data ), '+/', '-_' ), '=' ); } /** * convert url friendly base64 to bin */ function base64url_decode( string $data ): string { return base64_decode( strtr( $data, '-_', '+/' ) . str_repeat( '=', 3 - ( 3 + strlen( $data ) ) % 4 ) ); } ?> This should symmetrically convert one string and back in a url save manner. ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.137 (proxied: 62.112.9.167) ---- Manual Page -- https://php.net/manual/en/function.base64-encode.php Edit -- https://main.php.net/note/edit/129979 Del: integrated -- https://main.php.net/note/delete/129979/integrated Del: useless -- https://main.php.net/note/delete/129979/useless Del: bad code -- https://main.php.net/note/delete/129979/bad+code Del: spam -- https://main.php.net/note/delete/129979/spam Del: non-english -- https://main.php.net/note/delete/129979/non-english Del: in docs -- https://main.php.net/note/delete/129979/in+docs Del: other reasons-- https://main.php.net/note/delete/129979 Reject -- https://main.php.net/note/reject/129979 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221794) next »