W3docs

convert_uuencode()

The convert_uuencode() function is used to uuencode a string. The syntax of the convert_uuencode() function is as follows:

The convert_uuencode() function encodes a string using the uuencode algorithm. Uuencoding turns arbitrary binary data into a printable ASCII representation so it can travel safely through channels that only accept plain text — historically email attachments and Usenet posts, before MIME and Base64 became standard. The function is the encoding half of a pair; its counterpart, convert_uudecode(), reverses the process.

Important: convert_uuencode() was deprecated in PHP 7.4 and removed in PHP 8.0. All examples on this page run only on PHP 7.4 or older. For any new code, use base64_encode() / base64_decode(), which are not deprecated and produce URL- and email-safe output.

Syntax

string convert_uuencode ( string $data )
ParameterDescription
$dataThe string to encode. Required. May contain any bytes, including binary data.

Return value: the uuencoded form of $data as a string. The result is always longer than the input — uuencoding expands data by roughly 35% because it packs every 3 input bytes into 4 printable characters and adds per-line length headers plus an `/newline terminator.

Encoding a string

php— editable, runs on the server

On PHP 7.4 this prints the uuencoded block:

-2&5L;&\L(%=O<FQD(0``
`

The leading character on each data line encodes that line's byte count, the body is the encoded payload, and the final ` line marks the end of the stream. The output is not human-readable, but it contains only printable ASCII, which is the whole point.

Round-trip: encode then decode

Because uuencoding is lossless, passing the result back through convert_uudecode() returns the original bytes exactly:

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

$encoded = convert_uuencode($original);
$decoded = convert_uudecode($encoded);

echo $decoded;                       // Hello, World!
var_dump($decoded === $original);    // bool(true)
?>

This is the typical pattern: encode on the sending side, decode on the receiving side.

Encoding a file

You can uuencode the contents of a file by reading it with file_get_contents() and writing the result with file_put_contents():

<?php
$data    = file_get_contents("file_to_encode.txt");
$encoded = convert_uuencode($data);

file_put_contents("encoded_file.txt", $encoded);
?>

The new file holds a text-safe copy of the original that can be embedded in a message body. The receiver runs convert_uudecode(file_get_contents("encoded_file.txt")) to restore the bytes.

When would you use it?

Realistically, you would not in new code. Uuencode predates modern transport encodings and was dropped from PHP for that reason. You will only meet convert_uuencode() when maintaining legacy PHP that talks to an old system still expecting uuencoded payloads. For everything else:

  • Encoding binary for URLs, cookies, JSON, or email today: use base64_encode() / base64_decode().
  • Encoding text for HTTP headers or 7-bit email transport: see quoted_printable_encode().
  • Producing data interchange payloads: use json_encode().

Common gotchas

  • Removed in PHP 8. Calling convert_uuencode() on PHP 8.0+ raises a fatal Error. Guard legacy code with if (function_exists('convert_uuencode')) or migrate to Base64.
  • Not encryption. Uuencoding only reformats data; anyone can decode it. Never use it to hide secrets.
  • Larger output. Expect about a 35% size increase, so it is a poor fit where bandwidth or storage matters.

Practice

Practice
What does the convert_uuencode() function in PHP do?
What does the convert_uuencode() function in PHP do?
Was this page helpful?