PHP - Fonction imap_binary ()

Les fonctions PHP-IMAP vous aident à accéder aux comptes de messagerie, IMAP signifie IInternet Mail Aaccès Protocol en utilisant ces fonctions, vous pouvez également travailler avec les protocoles NNTP, POP3 et les méthodes d'accès aux boîtes aux lettres locales.

le imap_binary() La fonction accepte une valeur de chaîne représentant une chaîne de 8 bits en tant que paramètre et la convertit en une chaîne base64.

Syntaxe

imap_binary($str);

Paramètres

Sr. Non Paramètre et description
1

str (Mandatory)

Il s'agit d'une valeur de chaîne représentant la chaîne de 8 bits à convertir

Valeurs de retour

Cette fonction renvoie une valeur de chaîne qui est un format base64 de la chaîne donnée.

Version PHP

Cette fonction a été introduite pour la première fois dans la version 4 de PHP et fonctionne dans toutes les versions ultérieures.

Exemple

L'exemple suivant montre l'utilisation du imap_binary() fonction -

<html>
   <body>
      <?php
         //Establishing connection
         $url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "[email protected]";
         $pwd = "cohondob_123";
         $imap = imap_open($url, $id, $pwd);
         print("Connection established...."."<br>");
		 
         //Encoding the text
         $text = "Welcome to Tutorials point";		
         $encoded = imap_binary($text);
         print("Encoded value: ". "<br>");
         print($encoded);
		 
         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

Production

Cela générera la sortie suivante -

Connection established....
Encoded value:
V2VsY29tZSB0byBUdXRvcmlhbHNwb2ludA==

Exemple

Voici un autre exemple de cette fonction -

<html>
   <body>
      <?php
         //Establishing connection
         $url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "[email protected]";
         $pwd = "cohondob_123";
         $imap = imap_open($url, $id, $pwd);
         print("Connection established...."."<br>");
		 
         //fetching the body
         $text = imap_fetchbody($imap, 1, 1);
         
         //Encoding the mail contents
         $encoded = imap_binary($text);
         print("Encoded value of the mail contents: ". "<br>");
         print($encoded);
         print("<br>");

         //Decoding the mail content
         $res = imap_base64($encoded);
         print("Decoded value of the message: "."<br>");
         print($res);

         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

Production

Cela générera la sortie suivante -

Connection established....
Encoded value of the mail contents:
I3NhbXBsZV9tYWlsMQ0K
Decoded value of the message:
#sample_mail1