W3docs

convert_uudecode()

The convert_uudecode() function is used to decode a uuencoded string. The syntax of the convert_uudecode() function is as follows:

The convert_uudecode() function decodes a uuencoded string back into its original binary data. It is the exact inverse of convert_uuencode(): whatever convert_uuencode() produces, convert_uudecode() turns back into the bytes you started with.

This page covers the syntax, a complete round-trip example, how it behaves with files, the common gotchas, and when you would reach for it instead of a modern alternative like Base64.

What is uuencode?

uuencode (Unix-to-Unix encoding) is an old scheme for packing binary data into printable ASCII characters so it can travel safely through text-only channels such as email bodies or plain-text logs. Each group of 3 bytes is mapped to 4 printable characters, and the first character of every line stores that line's length.

In PHP you rarely produce uuencoded data by hand. You either receive it from a legacy system, or you create it yourself with convert_uuencode() and decode it later with convert_uudecode(). Note that convert_uudecode() works on the raw encoded body — it does not require (or strip) the classic begin 644 ... / end wrapper that the uuencode command-line tool adds.

Syntax

convert_uudecode(string $string): string|false

The function takes one parameter, $string — the uuencoded data to decode — and returns the decoded data. It returns false if the input is not valid uuencoded data.

Basic example: round-trip a string

The clearest way to see convert_uudecode() work is to encode a string and decode it back:

<?php
$original = "Hello, World!";

// Encode the data first.
$encoded = convert_uuencode($original);

// Decode it back to the original bytes.
$decoded = convert_uudecode($encoded);

echo $decoded;
?>

The output of this code is:

Hello, World!

The decoded value is byte-for-byte identical to the string we started with. This round-trip pattern is the reliable way to use the function: encode with convert_uuencode(), store or transmit the encoded text, then decode with convert_uudecode() on the other end.

Decoding a uuencoded file

A common real-world case is reading uuencoded content from a file and writing the decoded bytes back out:

<?php
$encoded = file_get_contents("encoded_file.txt");

if ($encoded === false) {
    die("Could not read the encoded file.\n");
}

$decoded = convert_uudecode($encoded);

if ($decoded === false) {
    die("The file did not contain valid uuencoded data.\n");
}

file_put_contents("decoded_file.txt", $decoded);
echo "Decoded " . strlen($decoded) . " bytes.\n";
?>

Here file_get_contents() reads the encoded text, convert_uudecode() decodes it, and file_put_contents() saves the original bytes to a new file. Checking the return values guards against a missing file or corrupted input.

Gotchas

  • It pairs with convert_uuencode(), not the shell uuencode tool. Data produced by the standalone uuencode command includes a begin 644 name header and an end footer. Feeding that wrapper straight to convert_uudecode() will not give you back your original bytes — strip the header/footer first, or re-encode the body with convert_uuencode().
  • Invalid input returns false. Always check the result before using it, especially when the data comes from a file or the network.
  • uuencode is not encryption. It only makes binary data printable; it provides no security. Anyone can decode it.

When to use it (and when not to)

Use convert_uudecode() when you must interoperate with a legacy system that already speaks uuencode. For new code, prefer Base64 (base64_encode() / base64_decode()): it is the modern standard for safely embedding binary data in JSON, data URIs, and HTTP headers, and it is supported everywhere.

Practice

Practice
What does the 'convert_uudecode' function in PHP do?
What does the 'convert_uudecode' function in PHP do?
Was this page helpful?