Applying UUEncode to a String in PHP


How To Apply UUEncode to a String?



UUEncode (Unix-to-Unix Encoding) is a simple algorithm to convert a string of any characters into a string of printable characters. UUEncode is reversible. The reverse algorithm is called UUDecode. PHP offers two functions for you to UUEncode or UUDecode a string: convert_uuencode() and convert_uudecode(), Here is a PHP script on how to use them:

$msgRaw = "
$msgEncoded = convert_uuencode($msgRaw);
$msgDecoded = convert_uudecode($msgEncoded);
if ($msgRaw === $msgDecoded) {
  print("Conversion OK\n");
  print("UUEncoded message:\n");
  print("UUDecoded message:\n");
} else {
  print("Conversion not OK:\n");

This script will print:

Conversion OK
UUEncoded message:
UUDecoded message:
From    To      Subject
Joe     Lee     Hello
Dan     Kia     Greeting<--

The output shows you that the UUEncode string is a multiple-line string with a special end-of-string mark \x20.


Replacing Characters in a String in PHP

Joining Multiple Strings in PHP

PHP Built-in Functions for Strings

⇑⇑ PHP Tutorials

2016-10-13, 1194👍, 0💬