note 92980 added to function.base64-decode

From: Date: Tue, 18 Aug 2009 04:05:21 +0000
Subject: note 92980 added to function.base64-decode
Groups: php.notes 
Request: Send a blank email to php-notes+get-159586@lists.php.net to get a copy of this message
I had some trouble trying to let base64_decode decode base64-strings longer than ~5k chars. The base64-decoding function is a homomorphism between modulo 4 and modulo 3-length segmented strings. That motivates a divide and conquer approach: Split the encoded string into substrings counting modulo 4 chars, then decode each substring and concatenate all of them. Then instead of $decoded = base64_decode($encoded); for big $encoded strings, it's saver to use $decoded = ""; for ($i=0; $i < ceil(strlen($encoded)/256); $i++) $decoded = $decoded . base64_decode(substr($encoded,$i*256,256)); where 256 can be replaced by a sufficiently small modulo 4 natural. ---- Server IP: 217.13.201.10 Probable Submitter: 87.143.165.157 ---- Manual Page -- http://www.php.net/manual/en/function.base64-decode.php Edit -- https://master.php.net/note/edit/92980 Del: integrated -- https://master.php.net/note/delete/92980/integrated Del: useless -- https://master.php.net/note/delete/92980/useless Del: bad code -- https://master.php.net/note/delete/92980/bad+code Del: spam -- https://master.php.net/note/delete/92980/spam Del: non-english -- https://master.php.net/note/delete/92980/non-english Del: in docs -- https://master.php.net/note/delete/92980/in+docs Del: other reasons-- https://master.php.net/note/delete/92980 Reject -- https://master.php.net/note/reject/92980 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#159586) next »