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


PHP Gdn_Format::ReplaceButProtectCodeBlocks方法代码示例

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


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

示例1: translateToHtml

 /**
  * Translate all emoji aliases to their corresponding Html image tags.
  *
  * Thanks to punbb 1.3.5 (GPL License) for function, which was largely
  * inspired from their do_smilies function.
  *
  * @param string $Text The actual user-submitted post
  * @return string Return the emoji-formatted post
  */
 public function translateToHtml($Text)
 {
     if (!$this->enabled) {
         return $Text;
     }
     $Text = ' ' . $Text . ' ';
     // First, translate all aliases. Canonical emoji will get translated
     // out of a loop.
     $emojiAliasList = $this->aliases;
     // Loop through and apply changes to all visible aliases from dropdown
     foreach ($emojiAliasList as $emojiAlias => $emojiCanonical) {
         $emojiFilePath = $this->getEmojiPath($emojiCanonical);
         if (strpos($Text, htmlentities($emojiAlias)) !== false) {
             $Text = Gdn_Format::ReplaceButProtectCodeBlocks('`(?<=[>\\s]|(&nbsp;))' . preg_quote(htmlentities($emojiAlias), '`') . '(?=\\W)`m', $this->img($emojiFilePath, $emojiAlias), $Text);
         }
     }
     // Second, translate canonical list, without looping.
     $ldelim = preg_quote($this->ldelim, '`');
     $rdelim = preg_quote($this->rdelim, '`');
     $emoji = $this;
     $Text = Gdn_Format::replaceButProtectCodeBlocks("`({$ldelim}[a-z0-9_+-]+{$rdelim})`i", function ($m) use($emoji) {
         $emoji_name = trim($m[1], ':');
         $emoji_path = $emoji->getEmojiPath($emoji_name);
         if ($emoji_path) {
             return $emoji->img($emoji_path, $emoji->ldelim . $emoji_name . $emoji->rdelim);
         } else {
             return $m[0];
         }
     }, $Text, true);
     return substr($Text, 1, -1);
 }
开发者ID:mcnasby,项目名称:datto-vanilla,代码行数:40,代码来源:class.emoji.php


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