The convert_uuencode() function encodes strings with the uuencode algorithm—a legacy binary-to-text format from Unix and early email. It turns raw bytes into printable ASCII and pairs with convert_uudecode() for decoding.
01
Encode to uuencode
Bytes → printable text.
02
One Parameter
Pass raw string data.
03
uuencode Pair
Decode with uudecode fn.
04
Binary Safe
Handles any byte value.
05
Legacy Format
Old email & Unix files.
06
vs Base64
Modern alternative.
Fundamentals
Definition and Usage
In PHP, convert_uuencode() takes any string—text or binary—and returns a uuencoded representation made of printable ASCII characters. Each output line starts with a length character, followed by encoded payload. Data longer than 45 bytes is split across multiple lines automatically.
💡
Beginner Tip
For new applications, use base64_encode() instead of uuencode. Learn convert_uuencode() when you maintain legacy code, study encoding history, or need output compatible with old uuencode tools.
Foundation
📝 Syntax
The convert_uuencode() function accepts one string parameter:
PHP
string convert_uuencode(string $string)
Parameters
$string — the data to encode. Can be plain text, binary bytes, or a mix of both.
Return Value
Returns the uuencoded string. Since PHP 8.0, encoding an empty string returns "" (previously it incorrectly returned false). The original input is not modified.
Cheat Sheet
⚡ Quick Reference
Encode
convert_uuencode($data)
original → uuencode
Decode
convert_uudecode($encoded)
uuencode → original
Round-trip
convert_uudecode(convert_uuencode($s))
Should equal $s
Modern
base64_encode($data)
Base64 instead
Hands-On
Examples Gallery
Run these examples in PHP 7+. Each demonstrates a common pattern beginners encounter with convert_uuencode().
📚 Getting Started
Encode plain text into uuencode format.
Example 1 — Encode a Simple String
The most direct way to see uuencode in action: pass a text string and inspect the encoded output.
The first character 0 (ASCII 48) indicates a 16-byte line. You can verify the round-trip with convert_uudecode($encoded), which restores the original multiline string exactly.
📈 Practical Patterns
Binary data, size overhead, and modern alternatives.
Example 3 — Encode Binary Data
uuencode handles any byte value—including NUL (\x00) and high bytes—making it useful for binary payloads.
PHP documentation notes uuencoded data is roughly 35% larger on average. Actual overhead varies with input length because of line-length prefixes and padding characters.
Example 5 — uuencode vs Base64 (Modern Alternative)
Compare legacy uuencode with Base64, the encoding standard used in modern web APIs and email.
Both encodings represent binary as text, but Base64 is slightly more compact and universally supported today. Use base64_encode() for new code; use uuencode only for legacy compatibility.
Applications
🚀 Common Use Cases
Legacy email attachments — produce uuencoded sections compatible with old Unix mail systems.
Maintaining old PHP scripts — understand and extend code that still calls uuencode functions.
Binary-to-text transport — represent binary data as printable ASCII for text-only channels.
Round-trip testing — verify encoded output decodes correctly with convert_uudecode().
Learning encoding history — compare uuencode with modern Base64 approaches.
🧠 How convert_uuencode() Works
1
PHP reads your raw data
You pass a string containing text, binary bytes, or both—any byte values are accepted.
Input
2
Bytes are grouped and translated
PHP splits data into 45-byte chunks, encodes each group into printable ASCII characters, and prefixes each line with a length character.
Transform
3
uuencoded string is returned
The result contains only printable ASCII—safe for email, logs, and text-only storage.
Output
=
📝
Printable encoded text
Ready to transmit, store, or decode with convert_uudecode().
Important
📝 Notes
Output does not include begin or end wrapper lines found in standalone uuencode files.
Encoded data is roughly 35–45% larger than the original, depending on input length.
Data longer than 45 bytes is automatically split across multiple encoded lines.
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.
Wrap Up
Conclusion
The convert_uuencode() function converts raw data into the legacy uuencode format as printable ASCII. It remains useful for legacy compatibility 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.
Verify round-trip with convert_uudecode() in tests
Use Base64 for all new binary-to-text encoding
Account for ~35% size increase when storing uuencoded data
Document when legacy uuencode output is required
Use bin2hex() to inspect binary input before encoding
❌ Don’t
Choose uuencode for new API or web application designs
Expect uuencode output to be human-readable content
Store binary in text columns when a BLOB field works
Assume full uuencode file headers are included automatically
Forget that PHP 8.4+ deprecates these functions
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about convert_uuencode()
Use these points whenever you encode data with uuencode in PHP.
5
Core concepts
📝01
Encode uuencode
Bytes → printable text.
Purpose
🔄02
uuencode Pair
Decode with uudecode.
Companion
🛠03
Binary Safe
Any byte value works.
Syntax
📧04
Legacy Email
Old Unix attachments.
Use case
⚙05
Use Base64
For new projects.
Modern
❓ Frequently Asked Questions
convert_uuencode() encodes a string using the uuencode algorithm, converting binary or text data into printable ASCII characters safe for text-only channels like old email systems.
string convert_uuencode(string $string). You pass the raw data and receive a uuencoded string. Since PHP 8.0, encoding an empty string returns an empty string instead of false.
Both turn binary into text, but uuencode is a legacy Unix format (lines starting with length characters). Base64 is the modern standard—more compact, faster, and supported everywhere in web APIs and email today.
No. PHP encodes the data block only—it does not add the begin or end wrapper lines found in standalone uuencode files on disk.
Use it when maintaining legacy systems, reproducing old uuencode output, or learning historical encoding. For new PHP projects, prefer base64_encode() and base64_decode().
Use convert_uudecode() on the encoded string. A round-trip test—convert_uudecode(convert_uuencode($data))—should always equal the original $data.