PHP convert_uuencode() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
String

Definition

In PHP, convert_uuencode() encodes binary data into a uuencoded ASCII string for text-safe transport.

You pass the data. It is required. Use convert_uudecode() to restore the original bytes.

Syntax

Call convert_uuencode on the data. Start with this line.

PHP
$encoded = convert_uuencode($data);
CallWhat it does
convert_uuencode("Hi")Returns uuencoded text.
convert_uudecode($encoded)Restores the original data.

Encoded output is longer than the input. This is not encryption.

Library declarations
PHP
convert_uuencode(string $data): string

Parameters

ParameterDescription
dataRequired. The binary or text data to encode.

Return Value

Return ValueDescription
stringThe uuencoded representation of the data.

PHP Examples

Example 1 — Encode a Simple String

Turn Hello into printable uuencode text.

PHP
<?php
echo convert_uuencode("Hello");
// %2&5L;&\`
// `

How It Works

  1. Input. Five bytes: H e l l o.
  2. Encode. convert_uuencode() maps them to printable ASCII.
  3. Lines. Output is usually multi-line (length char + data, then terminator).
  4. Not Base64. The alphabet and layout differ from Base64.

Example 2 — Encode, Then Decode

Prove the pair works: encode and decode should restore the original.

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

echo ($decoded === $original) ? "same" : "diff";
// same

How It Works

  1. Encode. convert_uuencode() builds the ASCII block.
  2. Decode. convert_uudecode() restores the bytes.
  3. Compare. Strict === confirms an exact match.
  4. Binary-safe. The same pattern works for NUL and other bytes.

Example 3 — Output Is Larger Than Input

Encoding always expands the data—plan storage and transport size accordingly.

PHP
<?php
$str = "Hello";
$enc = convert_uuencode($str);

echo strlen($str) . "\n";  // 5
echo strlen($enc) . "\n";  // 12
echo ($enc === $str) ? "same" : "grew";
// 5
// 12
// grew

How It Works

  1. Measure input. "Hello" is 5 bytes.
  2. Encode. The ASCII block includes length markers and newlines.
  3. Measure output. Length becomes 12 for this sample.
  4. Trade-off. Text-safe transport costs extra size (Base64 also expands, but is preferred for new work).

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. The original string is not modified.
Both turn binary into text, but uuencode is a legacy Unix format. Base64 is the modern standard—more compact and widely used 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().

Next: count_chars()

Learn how to count character frequencies in a string.

count_chars 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