PHP String quoted_printable_encode() Function



The PHP String quoted_printable_encode() function is used to convert an 8-bit string to a quoted-printable string. It basically returns a quoted printable string created as per the RFC2045. This function is like the imap_8bit() function, except this function does not need the IMAP module to work.

Syntax

Below is the syntax of the PHP String quoted_printable_encode() function −

string quoted_printable_encode ( string $string )

Parameters

This function accepts $string parameter which is the input string.

Return Value

The quoted_printable_encode() function returns the encoded string.

PHP Version

First introduced in core PHP 5.3.0, the quoted_printable_encode() function continues to function easily in PHP 7, and PHP 8.

Example 1

First we will show you the basic example of the PHP String quoted_printable_encode() function to convert a short string into a quoted-printable format.

<?php
   // Basic example of quoted_printable_encode
   $input = "Hello, World!";
   $encoded = quoted_printable_encode($input);

   echo "Encoded String: " . $encoded;
?>

Output

Here is the outcome of the following code −

Encoded String: Hello, World!

Example 2

In the below PHP code we will use the quoted_printable_encode() function and encode a string with the special characters, which are represented as hexadecimal values.

<?php
   // Encoding a string with special characters
   $input = "Hello! How's it going?  2024";
   $encoded = quoted_printable_encode($input);

   echo "Original String: " . $input . "\n";
   echo "Encoded String: " . $encoded;
?> 

Output

This will generate the below output −

Original String: Hello! How's it going?  2024
Encoded String: Hello! How's it going? =C2=A9 2024

Example 3

Now the below code the quoted_printable_encode() function is used to encode a multiline string in which line breaks are saved during encoding.

<?php
   // Encoding a multiline string
   $input = "Hello,\nThis is a test.\nQuoted-printable encoding is fun!";
   $encoded = quoted_printable_encode($input);

   echo "Original Multiline String:\n" . $input . "\n\n";
   echo "Encoded String:\n" . $encoded;
?> 

Output

This will create the below output −

Original Multiline String:
Hello,
This is a test.
Quoted-printable encoding is fun!

Encoded String:
Hello,=0AThis is a test.=0AQuoted-printable encoding is fun!
php_function_reference.htm
Advertisements