PHP - imap_utf7_encode() 函式



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

**imap_utf7_encode()** 函式接受 ISO-8859-1 字串作為引數,並將其編碼為 UTF-7 格式。

語法

imap_utf7_decode($txt);

引數

序號 引數及描述
1

txt (必填)

這是一個字串值,表示 ISO-8859-1 字串。

返回值

此函式返回一個包含給定字串編碼值的字串。

PHP 版本

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

示例

以下示例演示了 **imap_utf7_decode()** 函式的使用。

<html>
   <body>
      <?php
         //Decoding the string
         $utf7 = '[Gmail]/&BBIEMAQ2BD0EPgQ1−';
         $res = imap_utf7_decode($utf7);
         print("Decoded value: ".$res."<br>");
         
         //Encoding the result again
         $encoded_val = imap_utf7_encode($res);
         print("Encoded value: ".$encoded_val);
      ?>
   </body>
</html>

輸出

這將生成以下輸出:

Decoded value: [Gmail]/06=>5
Encoded value: [Gmail]/&BBIE-0&BA-6&BA-=&BA->&BA-5

示例

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

<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>"); 
         //Creating a mailbox
         $newmailbox = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX.test";
         $res = imap_createmailbox($mailbox, imap_utf7_encode($newmailbox));		 
         if($res){
            print("Mailbox created successfully");
         }else{
            print("Error occurred");
         }		 
      ?>
   </body>
</html>

輸出

上述程式生成以下輸出:

Connection established....
Mailbox created successfully
php_function_reference.htm
廣告

© . All rights reserved.