Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
|
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 24th, 2003, 01:29 PM
Registered User
 
Join Date: Jul 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default uudecoding in PHP

I would like a function or some source code that can uudecode a string. This can be accomplished in Perl easily with $decoded = unpack("u", $encoded); Encoding data with: $encoded = pack("u", org_string);

I have found that PHP has a pack function but did not include a "u" (uudecode) option. I found an example that supposedly works, but after testing it, it does not decode properly. Here is the example:

function uudecode($encode)
{
    $b64chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklm nopqrstuvwxyz0123456789+/";

    $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 ($encode);
}

I found a good site that explains in depth how uuencoding works, it is at http://www.drbob42.com/books/uucode.htm
There is a Pascal example that I have not yet tried converting into PHP.

The character set used for decoding was different from the example, here are the characters from the web site.
$b64chars="`!\"#$%&'()*+,-./0123456789:;<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_";

I tried substituting the characters into the function and it also did not work.


Walter G.





Similar Threads
Thread Thread Starter Forum Replies Last Post
chapter 10 Emailing with php - firstmail.php vijdev BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 July 19th, 2007 01:12 AM
Beg. PHP 5 > Ch. 11 - fetch_field.php crater BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 0 January 2nd, 2007 12:20 PM
PHP Warning: PHP Startup: Unable to load dynamic l surendran Beginning PHP 1 May 29th, 2006 08:49 AM
begin php & mysql - chapter 12, user_form.php jon_stubber Beginning PHP 1 March 9th, 2006 10:57 AM
Error: movie.php & commit.php on p182-186, ch6 willburke BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 October 12th, 2004 02:48 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.