PHP convert_uudecode() Function

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
String Functions

What You’ll Learn

The convert_uudecode() function decodes strings encoded with the uuencode algorithm—a legacy binary-to-text format from Unix and early email systems. It pairs with convert_uuencode() and is useful when working with old encoded data.

01

Decode uuencode

Text back to bytes.

02

One Parameter

Pass encoded string.

03

uuencode Pair

Works with encode fn.

04

Returns false

On decode failure.

05

Legacy Format

Old email & Unix files.

06

vs Base64

Modern alternative.

Definition and Usage

In PHP, convert_uudecode() takes a uuencoded string and returns the original data. uuencode converts binary bytes into printable ASCII so they could travel through text-only systems. Each encoded line typically starts with a character indicating the line length, followed by encoded payload characters.

💡
Beginner Tip

For new applications, use base64_encode() and base64_decode() instead of uuencode. Learn convert_uudecode() when you encounter legacy files, old PHP scripts, or historical email attachments that use uuencoding.

📝 Syntax

The convert_uudecode() function accepts one string parameter:

PHP
string|false convert_uudecode(string $string)

Parameters

  • $string — the uuencoded data to decode. Must be valid uuencode output (typically produced by convert_uuencode()).

Return Value

Returns the decoded string on success, or false if decoding fails. The original input is not modified.

⚡ Quick Reference

Decode
convert_uudecode($encoded)

uuencode → original

Encode
convert_uuencode($data)

original → uuencode

Round-trip
convert_uudecode(convert_uuencode($s))

Should equal $s

Modern
base64_decode($b64)

Base64 instead

Examples Gallery

Run these examples in PHP 7+. Each demonstrates a common pattern beginners encounter with convert_uudecode().

📚 Getting Started

Decode uuencoded data back to readable text.

Example 1 — Encode Then Decode (Recommended)

The clearest way to learn: create uuencoded data with convert_uuencode(), then decode it.

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

echo "Original: $original\n";
echo "Encoded:\n$encoded\n";
echo "Decoded:  $decoded\n";
?>

How It Works

  • convert_uuencode() wraps the text in uuencode format (the first character, such as +, encodes the line length).
  • convert_uudecode() strips the encoding and restores the original bytes.
  • Encoded output contains only printable ASCII characters.

Example 2 — Verify Round-Trip Match

Confirm that encoding and decoding recovers the exact original string.

PHP
<?php
$messages = ["test", "Binary\x00data", "Multi\nline\ntext"];

foreach ($messages as $msg) {
    $back = convert_uudecode(convert_uuencode($msg));
    $ok   = ($back === $msg) ? "yes" : "no";
    echo "Match ($ok): " . json_encode($msg) . "\n";
}
?>

How It Works

uuencode preserves all byte values including NUL bytes and newlines—unlike some text encodings that cannot represent every binary value.

📈 Practical Patterns

Legacy data, error handling, and modern alternatives.

Example 3 — Decode a Pre-Encoded uuencode String

When you already have uuencoded data from a file or old email, pass it directly to convert_uudecode().

PHP
<?php
// uuencoded form of "test\ntext test a" (legacy sample)
$encoded = "0=&5S=`IT97AT('1E<W0@86X@97)S='9E(&9O<F5C=\"!O8FH-,3`I";

$decoded = convert_uudecode($encoded);

echo "Decoded:\n$decoded\n";
echo "Length: " . strlen($decoded) . " bytes\n";
?>

How It Works

The leading 0= is part of the uuencode line format. Real-world uuencoded files may contain multiple lines; PHP decodes the entire block you provide.

Example 4 — Handling Invalid Input

Passing plain text that was never uuencoded usually fails or produces garbage—always validate your source.

PHP
<?php
$plainText = "This is not uuencoded";
$result    = convert_uudecode($plainText);

if ($result === false) {
    echo "Decoding failed.\n";
} else {
    echo "Unexpected result: " . bin2hex($result) . "\n";
}

// Safe pattern: only decode known uuencode output
$safe = convert_uuencode("Known data");
echo convert_uudecode($safe) . "\n";
?>

How It Works

Always check for false when decoding data from untrusted sources. Only decode strings you know were produced by convert_uuencode() or a compatible uuencode tool.

Example 5 — uuencode vs Base64 (Modern Alternative)

Compare legacy uuencode with Base64, the encoding used in modern web APIs and email.

PHP
<?php
$data = "Sample binary\xFF\xFE data";

$uu  = convert_uuencode($data);
$b64 = base64_encode($data);

echo "uuencode length:  " . strlen($uu) . "\n";
echo "Base64 length:    " . strlen($b64) . "\n";

echo "uudecode match:   " . (convert_uudecode($uu) === $data ? "yes\n" : "no\n");
echo "base64 match:     " . (base64_decode($b64) === $data ? "yes\n" : "no\n");
?>

How It Works

Both encodings represent binary as text, but Base64 is more compact and universally supported today. Use Base64 for new code; use uudecode only for legacy compatibility.

🚀 Common Use Cases

  • Legacy email attachments — decode uuencoded sections in old Unix mail files.
  • Maintaining old PHP scripts — understand code that still calls uuencode functions.
  • Historical file formats — read uuencoded data from 1980s–1990s software archives.
  • Round-trip testing — verify convert_uuencode() output decodes correctly.
  • Learning encoding history — compare uuencode with modern Base64 approaches.

🧠 How convert_uudecode() Works

1

PHP reads uuencoded text

You pass a string containing uuencode lines—printable ASCII representing binary data.

Input
2

Characters are translated to bytes

PHP parses each uuencode line, maps encoded characters back to their original byte values, and concatenates the result.

Transform
3

Original data is returned

The decoded string contains the same bytes as before encoding—text, binary, or mixed.

Output
=

Restored content

Ready for display, file writing, or further processing.

📝 Notes

  • Input must be valid uuencode output—plain text produces unreliable results.
  • Always pair with convert_uuencode() when you control both sides of the encoding.
  • Check for false return value when decoding external or untrusted data.
  • For new projects, prefer base64_encode() / base64_decode().
  • uuencode and uudecode functions were deprecated in PHP 8.4; plan migrations for long-term PHP 9 compatibility.

Conclusion

The convert_uudecode() function restores data from the legacy uuencode format. It remains useful for reading old encoded content and understanding historical PHP code, even though Base64 has replaced uuencode in modern applications.

Encode with convert_uuencode(), decode with convert_uudecode(), and reach for Base64 when building anything new.

💡 Best Practices

✅ Do

  • Verify round-trip with convert_uuencode() in tests
  • Check for false when decoding external data
  • Use Base64 for all new binary-to-text encoding
  • Document when legacy uuencode data is expected
  • Use bin2hex() to inspect unexpected binary output

❌ Don’t

  • Decode arbitrary plain text expecting meaningful results
  • Choose uuencode for new API or web application designs
  • Assume uuencode output is human-readable content
  • Skip validation on data from untrusted sources
  • Forget that PHP 8.4+ deprecates these functions

Key Takeaways

Knowledge Unlocked

Five things to remember about convert_uudecode()

Use these points whenever you work with uuencoded strings in PHP.

5
Core concepts
🔄 02

uuencode Pair

Inverse of encode.

Companion
🛠 03

false on Fail

Check return value.

Syntax
📧 04

Legacy Email

Old Unix attachments.

Use case
05

Use Base64

For new projects.

Modern

❓ 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 binary-to-text encoding from Unix systems. It represents binary data as printable ASCII characters so it could be sent through email and text-only channels before Base64 became standard.
convert_uudecode() handles the older uuencode format (lines starting with length characters like M). 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 files, old email attachments, or maintaining code that still produces uuencode output. For new projects, prefer Base64 with base64_encode() and base64_decode().
Decoding invalid or plain text input typically returns false or produces unexpected binary output. Always ensure the input was genuinely uuencoded before calling this function.

Explore More PHP String Functions

Continue with convert_uuencode(), count_chars(), and the rest of the string function reference.

Next: convert_uuencode() →

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.

6 people found this page helpful