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


PHP Utils::truncateHTML方法代码示例

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


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

示例1: summary

 /**
  * Get the summary.
  *
  * @param  int    $size Max summary size.
  * @return string
  */
 public function summary($size = null)
 {
     /** @var Config $config */
     $config = self::getGrav()['config']->get('site.summary');
     if (isset($this->header->summary)) {
         $config = array_merge($config, $this->header->summary);
     }
     // Return summary based on settings in site config file
     if (!$config['enabled']) {
         return $this->content();
     }
     // Set up variables to process summary from page or from custom summary
     if ($this->summary === null) {
         $content = $this->content();
         $summary_size = $this->summary_size;
     } else {
         $content = $this->summary;
         $summary_size = mb_strlen($this->summary);
     }
     // Return calculated summary based on summary divider's position
     $format = $config['format'];
     // Return entire page content on wrong/ unknown format
     if (!in_array($format, array('short', 'long'))) {
         return $content;
     } elseif ($format === 'short' && isset($summary_size)) {
         return mb_substr($content, 0, $summary_size);
     }
     // Get summary size from site config's file
     if (is_null($size)) {
         $size = $config['size'];
     }
     // If the size is zero, return the entire page content
     if ($size === 0) {
         return $content;
         // Return calculated summary based on defaults
     } elseif (!is_numeric($size) || $size < 0) {
         $size = 300;
     }
     return Utils::truncateHTML($content, $size);
 }
开发者ID:realitygaps,项目名称:grav_ynh,代码行数:46,代码来源:Page.php

示例2: summary

 /**
  * Get the summary.
  *
  * @param int $size  Max summary size.
  * @return string
  */
 public function summary($size = null)
 {
     $content = $this->content();
     // Return calculated summary based on summary divider's position
     if (!$size && isset($this->summary_size)) {
         return substr($content, 0, $this->summary_size);
     }
     // Return calculated summary based on setting in site config file
     /** @var Config $config */
     $config = self::$grav['config'];
     if (!$size && $config->get('site.summary.size')) {
         $size = $config->get('site.summary.size');
     }
     // Return calculated summary based on defaults
     if (!$size) {
         $size = 300;
     }
     return Utils::truncateHTML($content, $size);
 }
开发者ID:qbi,项目名称:datenknoten.me,代码行数:25,代码来源:Page.php


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