当前位置: 首页>>代码示例>>PHP>>正文


PHP core_text::encode_mimeheader方法代码示例

本文整理汇总了PHP中core_text::encode_mimeheader方法的典型用法代码示例。如果您正苦于以下问题:PHP core_text::encode_mimeheader方法的具体用法?PHP core_text::encode_mimeheader怎么用?PHP core_text::encode_mimeheader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在core_text的用法示例。


在下文中一共展示了core_text::encode_mimeheader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: encodeHeader

 /**
  * Use internal moodles own core_text to encode mimeheaders.
  * Fall back to phpmailers inbuilt functions if not 
  */
 public function encodeHeader($str, $position = 'text')
 {
     $encoded = core_text::encode_mimeheader($str, $this->CharSet);
     if ($encoded !== false) {
         $encoded = str_replace("\n", $this->LE, $encoded);
         if ($position === 'phrase') {
             return "\"{$encoded}\"";
         }
         return $encoded;
     }
     return parent::encodeHeader($str, $position);
 }
开发者ID:educacionbe,项目名称:cursos,代码行数:16,代码来源:moodle_phpmailer.php

示例2: test_encode_mimeheader

 /**
  * Tests the static encode_mimeheader method.
  */
 public function test_encode_mimeheader()
 {
     $str = "Žluťoučký koníček";
     $this->assertSame('=?utf-8?B?xb1sdcWlb3XEjWvDvSBrb27DrcSNZWs=?=', core_text::encode_mimeheader($str));
 }
开发者ID:rushi963,项目名称:moodle,代码行数:8,代码来源:text_test.php

示例3: test_encode_mimeheader

 /**
  * Tests the static encode_mimeheader method.
  * This also tests method moodle_phpmailer::encodeHeader that calls core_text::encode_mimeheader
  */
 public function test_encode_mimeheader()
 {
     global $CFG;
     require_once $CFG->libdir . '/phpmailer/moodle_phpmailer.php';
     $mailer = new moodle_phpmailer();
     // Encode short string with non-latin characters.
     $str = "Žluťoučký koníček";
     $encodedstr = '=?utf-8?B?xb1sdcWlb3XEjWvDvSBrb27DrcSNZWs=?=';
     $this->assertSame($encodedstr, core_text::encode_mimeheader($str));
     $this->assertSame($encodedstr, $mailer->encodeHeader($str));
     $this->assertSame('"' . $encodedstr . '"', $mailer->encodeHeader($str, 'phrase'));
     // Encode short string without non-latin characters. Make sure the quotes are escaped in quoted email headers.
     $latinstr = 'text"with quotes';
     $this->assertSame($latinstr, core_text::encode_mimeheader($latinstr));
     $this->assertSame($latinstr, $mailer->encodeHeader($latinstr));
     $this->assertSame('"text\\"with quotes"', $mailer->encodeHeader($latinstr, 'phrase'));
     // Encode long string without non-latin characters.
     $longlatinstr = 'This is a very long text that still should not be split into several lines in the email headers because ' . 'it does not have any non-latin characters. The "quotes" and \\backslashes should be escaped only if it\'s a part of email address';
     $this->assertSame($longlatinstr, core_text::encode_mimeheader($longlatinstr));
     $this->assertSame($longlatinstr, $mailer->encodeHeader($longlatinstr));
     $longlatinstrwithslash = preg_replace(['/\\\\/', "/\"/"], ['\\\\\\', '\\"'], $longlatinstr);
     $this->assertSame('"' . $longlatinstrwithslash . '"', $mailer->encodeHeader($longlatinstr, 'phrase'));
     // Encode long string with non-latin characters.
     $longstr = "Неопознанная ошибка в файле C:\\tmp\\: \"Не пользуйтесь виндоуз\"";
     $encodedlongstr = "=?utf-8?B?0J3QtdC+0L/QvtC30L3QsNC90L3QsNGPINC+0YjQuNCx0LrQsCDQsiDRhNCw?=\n =?utf-8?B?0LnQu9C1IEM6XHRtcFw6ICLQndC1INC/0L7Qu9GM0LfRg9C50YLQtdGB?=\n =?utf-8?B?0Ywg0LLQuNC90LTQvtGD0Lci?=";
     $this->assertSame($encodedlongstr, $mailer->encodeHeader($longstr));
     $this->assertSame('"' . $encodedlongstr . '"', $mailer->encodeHeader($longstr, 'phrase'));
 }
开发者ID:evltuma,项目名称:moodle,代码行数:32,代码来源:text_test.php

示例4: encodeHeader

 /**
  * Use internal moodles own core_text to encode mimeheaders.
  * Fall back to phpmailers inbuilt functions if not 
  */
 public function encodeHeader($str, $position = 'text')
 {
     $encoded = core_text::encode_mimeheader($str, $this->CharSet);
     if ($encoded !== false) {
         if ($position === 'phrase') {
             // Escape special symbols in each line in the encoded string, join back together and enclose in quotes.
             $chunks = preg_split("/\\n/", $encoded);
             $chunks = array_map(function ($chunk) {
                 return addcslashes($chunk, "..\\\"");
             }, $chunks);
             return '"' . join($this->LE, $chunks) . '"';
         }
         return str_replace("\n", $this->LE, $encoded);
     }
     return parent::encodeHeader($str, $position);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:20,代码来源:moodle_phpmailer.php


注:本文中的core_text::encode_mimeheader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。