PHP - imap_base64() 函式



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

**imap_base64()** 函式接受一個字串值作為引數,該字串值表示使用 base-64 編碼的文字,對其進行解碼並返回結果。

**imap_binary()** 函式 notranslate"> imap_append($txt);

引數

序號 引數和描述
1

txt (必填)

這是一個字串值,表示編碼的文字。

返回值

此函式返回一個字串值,表示給定訊息的解碼格式。

PHP 版本

此函式首次在 PHP 4 版本中引入,並在所有後續版本中有效。

示例

以下示例演示了 **imap_base64()** 函式的用法:

<html>
   <body>
      <?php
         $url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "tutorialspoint.test@gmail.com";
         $pwd = "cohondob_123";
         $mailbox = imap_open($url, $id, $pwd);
         print("Connection established....");
         print("<br>");
         $msg = "RGFuJ3MgVG9vbHMgYXJlIGNvb2wh";		 
         
         //Converting base64 code
         $res = imap_base64($msg);
         print($res);
      ?>
   </body>
</html>

輸出

這將生成以下輸出:

Connection established....
Dan's Tools are cool!

示例

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

<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
廣告
© . All rights reserved.