note 20080 modified in function.base64-decode by vrana

From: Date: Tue, 17 Aug 2004 14:52:39 +0000
Subject: note 20080 modified in function.base64-decode by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79973@lists.php.net to get a copy of this message
I used to do uudecode as a C module, but I've discovered a really fast way to do it in PHP. Here it is: <?php function uudecode($encode) { $b64chars="ABCDEFGHIJKLMNOPQRSTUVWXYZ\ abcdefghijklmnopqrstuvwxyz0123456789+/"; $encode = preg_replace("/^./m","",$encode); $encode = preg_replace("/\n/m","",$encode); for($i=0; $i<strlen($encode); $i++) { if ($encode[$i] == '`') $encode[$i] = ' '; $encode[$i] = $b64chars[ord($encode[$i])-32]; } while(strlen($encode) % 4) $encode .= "="; return base64_decode($encode); } ?> This is the PHP equivalent to perl's unpack("u",___). That is, you need to strip the 'begin' and 'end' lines from the typical uuencoded file. --was-- I used to do uudecode as a C module, but I've discovered a really fast way to do it in PHP. Here it is: function uudecode($encode) { $b64chars="ABCDEFGHIJKLMNOPQRSTUVWXYZ\ abcdefghijklmnopqrstuvwxyz0123456789+/"; $encode = preg_replace("/^./m","",$encode); $encode = preg_replace("/\n/m","",$encode); for($i=0; $i<strlen($encode); $i++) { if ($encode[$i] == '`') $encode[$i] = ' '; $encode[$i] = $b64chars[ord($encode[$i])-32]; } while(strlen($encode) % 4) $encode .= "="; return base64_decode($encode); } This is the PHP equivalent to perl's unpack("u",___). That is, you need to strip the 'begin' and 'end' lines from the typical uuencoded file. http://php.net/manual/en/function.base64-decode.php

« previous php.notes (#79973) next »