PHP - imap_binary() 函式



PHP−IMAP 函式幫助您訪問電子郵件帳戶,IMAP 代表 **I**nternet **M**ail **A**ccess **P**rotocol,使用這些函式您還可以使用 NNTP、POP3 協議和本地郵箱訪問方法。

imap_binary() 函式接受一個表示 8 位字串的字串值作為引數,並將其轉換為 base64 字串。

語法

imap_binary($str);

引數

序號 引數和描述
1

str (必填)

這是一個表示要轉換的 8 位字串的字串值

返回值

此函式返回一個字串值,該值是給定字串的 base64 格式。

PHP 版本

此函式最初在 PHP 4 版本中引入,並在所有後續版本中均有效。

示例

以下示例演示了 imap_binary() 函式的使用 −

<html>
   <body>
      <?php
         //Establishing connection
         $url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "tutorialspoint.test@gmail.com";
         $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>

輸出

這將生成以下輸出 −

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

示例

以下是此函式的另一個示例 −

<html>
   <body>
      <?php
         //Establishing connection
         $url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "tutorialspoint.test@gmail.com";
         $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>

輸出

這將生成以下輸出 −

Connection established....
Encoded value of the mail contents:
I3NhbXBsZV9tYWlsMQ0K
Decoded value of the message:
#sample_mail1
php_function_reference.htm
廣告