PHP convert_uudecode() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
String

Definition

In PHP, convert_uudecode() decodes a uuencoded string back into the original binary data.

You pass the encoded string. It is required. Pair it with convert_uuencode() for round-trips.

Syntax

Call convert_uudecode on the encoded text. Start with this line.

PHP
$bin = convert_uudecode($encoded);
CallWhat it does
convert_uudecode($encoded)Restores the original bytes.
convert_uuencode($bin)Encodes binary for transport.

Invalid uuencoded input can return false or unexpected data—validate first.

Library declarations
PHP
convert_uudecode(string $data): string|false

Parameters

ParameterDescription
dataRequired. The uuencoded string to decode.

Return Value

Return ValueDescription
string|falseDecoded binary data, or false on failure.

PHP Examples

Example 1 — Encode, Then Decode

The safest way to learn: create uuencode with convert_uuencode(), then reverse it.

PHP
<?php
$original = "Hello";
$encoded = convert_uuencode($original);
$decoded = convert_uudecode($encoded);

echo $decoded;
// Hello

How It Works

  1. Start. $original is plain text Hello.
  2. Encode. convert_uuencode() turns it into printable ASCII.
  3. Decode. convert_uudecode() restores the bytes.
  4. Match. $decoded equals Hello again.

Example 2 — Handle Invalid Input

Always check for false before treating the result as a string.

PHP
<?php
$result = convert_uudecode("not uuencoded text");

if ($result === false) {
    echo "decode failed";
} else {
    echo $result;
}
// decode failed

How It Works

  1. Bad input. Plain text is not valid uuencode.
  2. Call. convert_uudecode() fails and returns false.
  3. Strict check. Use === false (decoded data could be empty string).
  4. Branch. Print an error instead of echoing false as empty.

Example 3 — Round-Trip Binary Bytes

uuencode is binary-safe—NUL and non-text bytes survive a round-trip.

PHP
<?php
$raw = "A" . chr(0) . "B";
$back = convert_uudecode(convert_uuencode($raw));

echo strlen($back) . "\n";           // 3
echo ($back === $raw) ? "same" : "diff";
// 3
// same

How It Works

  1. Build bytes. A, a NUL byte (chr(0)), then B.
  2. Round-trip. Encode then decode in one expression.
  3. Length. Still 3 bytes—NUL was preserved.
  4. Equality. $back === $raw confirms an exact restore.

Frequently Asked Questions

convert_uudecode() decodes a string that was encoded with the uuencode algorithm, returning the original binary or text data. It reverses the encoding performed by convert_uuencode().
string|false convert_uudecode(string $string). You pass the uuencoded string and receive the decoded data, or false if decoding fails.
uuencode is a legacy Unix binary-to-text encoding. It represents binary data as printable ASCII so it could travel through email and text-only channels before Base64 became the common standard.
convert_uudecode() handles the older uuencode format. base64_decode() handles Base64, which is the modern standard for encoding binary data in email, JSON, and web APIs.
Use it when reading legacy uuencoded data or maintaining old code. For new projects, prefer Base64 with base64_encode() and base64_decode().

Next: convert_uuencode()

Learn how to encode binary data with the uuencode algorithm.

convert_uuencode tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful