Horje
PHP imap_binary() Function

The imap_binary() function is an inbuilt function in PHP that is used to convert the 8-bit string into the base64 encoding. This function is used by some IMAP servers to represent mailbox names that contain non-ASCII characters or certain ASCII characters that are special in IMAP.

Syntax:

imap_binary(string $string) : string | false

Parameters: This function accepts only one parameter which is described below.

  • $string: This is the string parameter that contains the 8-bit string.

Return Values: The imap_binary() function if successfully executed will return a base64 encoded string otherwise this function will return “false”.

Note: Before using this function check if this is available in your environment or not. If not, then type this command

 apt-get install php-imap

References:

 

Program 1: The following program demonstrates the imap_binary() function.

PHP

<?php
  
$string = "horje";
$eightBitData = imap_binary($string);
  
// Output the result
echo "Original data: $string\n";
echo "Converted base64 data: $eightBitData\n";
  
?>

Output:

Original data: horje
Converted base64 data: Z2Vla3Nmb3JnZWVrcw==

Program 2: The following program demonstrates the imap_binary() function.

PHP

<?php
  
$utf7data1 = "&ZeVnLIqe-";
$utf7data2 = "&BfAEEAbABlAG4ALwA-";
  
// Check if the imap_binary() function exists
if (function_exists("imap_binary")) {
    $eightBitData1 = imap_binary($utf7data1);
    $eightBitData2 = imap_binary($utf7data2);
  
    // Output the results
    echo "Original UTF-7 data 1: $utf7data1\n";
    echo "Converted 8-bit data 1: $eightBitData1\n\n";
  
    echo "Original UTF-7 data 2: $utf7data2\n";
    echo "Converted 8-bit data 2: $eightBitData2\n";
} else {
    echo "imap_binary() function is not available"
        . " in this environment.\n";
}
  
?>

Output:

Original UTF-7 data 1: &ZeVnLIqe-
Converted 8-bit data 1: JlplVm5MSXFlLQ==
Original UTF-7 data 2: &BfAEEAbABlAG4ALwA-
Converted 8-bit data 2: JkJmQUVFQWJBQmxBRzRBTHdBLQ==

Reference: https://www.php.net/manual/en/function.imap-binary.php




Reffered: https://www.geeksforgeeks.org


PHP

Related
PHP imap_base64() Function PHP imap_base64() Function
PHP finfo_close() Function PHP finfo_close() Function
PHP finfo_set_flags() Function PHP finfo_set_flags() Function
PHP ob_get_contents() Function PHP ob_get_contents() Function
PHP SplFileObject fpassthru() Function PHP SplFileObject fpassthru() Function

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
11