當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。