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


PHP CharsetConverter::crop方法代码示例

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


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

示例1: makeTitle

 /**
  * Returns the title of the search result row
  *
  * @param array $row Result row
  * @return string Title from row
  */
 public function makeTitle($row)
 {
     $add = '';
     if ($this->multiplePagesType($row['item_type'])) {
         $dat = unserialize($row['cHashParams']);
         $pp = explode('-', $dat['key']);
         if ($pp[0] != $pp[1]) {
             $add = ', ' . $this->pi_getLL('word_pages') . ' ' . $dat['key'];
         } else {
             $add = ', ' . $this->pi_getLL('word_page') . ' ' . $pp[0];
         }
     }
     $outputString = $this->charsetConverter->crop('utf-8', $row['item_title'], $this->conf['results.']['titleCropAfter'], $this->conf['results.']['titleCropSignifier']);
     return $outputString . $add;
 }
开发者ID:dachcom-digital,项目名称:TYPO3.CMS,代码行数:21,代码来源:SearchFormController.php

示例2: markupSWpartsOfString

 /**
  * Marks up the search words from $this->searchWords in the $str with a color.
  *
  * @param string $str Text in which to find and mark up search words. This text is assumed to be UTF-8 like the search words internally is.
  * @return string Processed content
  */
 protected function markupSWpartsOfString($str)
 {
     $htmlParser = GeneralUtility::makeInstance(HtmlParser::class);
     // Init:
     $str = str_replace(' ', ' ', $htmlParser->bidir_htmlspecialchars($str, -1));
     $str = preg_replace('/\\s\\s+/', ' ', $str);
     $swForReg = array();
     // Prepare search words for regex:
     foreach ($this->searchWords as $d) {
         $swForReg[] = preg_quote($d['sword'], '/');
     }
     $regExString = '(' . implode('|', $swForReg) . ')';
     // Split and combine:
     $parts = preg_split('/' . $regExString . '/i', ' ' . $str . ' ', 20000, PREG_SPLIT_DELIM_CAPTURE);
     // Constants:
     $summaryMax = $this->settings['results.']['markupSW_summaryMax'];
     $postPreLgd = $this->settings['results.']['markupSW_postPreLgd'];
     $postPreLgd_offset = $this->settings['results.']['markupSW_postPreLgd_offset'];
     $divider = $this->settings['results.']['markupSW_divider'];
     $occurencies = (count($parts) - 1) / 2;
     if ($occurencies) {
         $postPreLgd = MathUtility::forceIntegerInRange($summaryMax / $occurencies, $postPreLgd, $summaryMax / 2);
     }
     // Variable:
     $summaryLgd = 0;
     $output = array();
     // Shorten in-between strings:
     foreach ($parts as $k => $strP) {
         if ($k % 2 == 0) {
             // Find length of the summary part:
             $strLen = $this->charsetConverter->strlen('utf-8', $parts[$k]);
             $output[$k] = $parts[$k];
             // Possibly shorten string:
             if (!$k) {
                 // First entry at all (only cropped on the frontside)
                 if ($strLen > $postPreLgd) {
                     $output[$k] = $divider . preg_replace('/^[^[:space:]]+[[:space:]]/', '', $this->charsetConverter->crop('utf-8', $parts[$k], -($postPreLgd - $postPreLgd_offset)));
                 }
             } elseif ($summaryLgd > $summaryMax || !isset($parts[$k + 1])) {
                 // In case summary length is exceed OR if there are no more entries at all:
                 if ($strLen > $postPreLgd) {
                     $output[$k] = preg_replace('/[[:space:]][^[:space:]]+$/', '', $this->charsetConverter->crop('utf-8', $parts[$k], $postPreLgd - $postPreLgd_offset)) . $divider;
                 }
             } else {
                 if ($strLen > $postPreLgd * 2) {
                     $output[$k] = preg_replace('/[[:space:]][^[:space:]]+$/', '', $this->charsetConverter->crop('utf-8', $parts[$k], $postPreLgd - $postPreLgd_offset)) . $divider . preg_replace('/^[^[:space:]]+[[:space:]]/', '', $this->charsetConverter->crop('utf-8', $parts[$k], -($postPreLgd - $postPreLgd_offset)));
                 }
             }
             $summaryLgd += $this->charsetConverter->strlen('utf-8', $output[$k]);
             // Protect output:
             $output[$k] = htmlspecialchars($output[$k]);
             // If summary lgd is exceed, break the process:
             if ($summaryLgd > $summaryMax) {
                 break;
             }
         } else {
             $summaryLgd += $this->charsetConverter->strlen('utf-8', $strP);
             $output[$k] = '<strong class="tx-indexedsearch-redMarkup">' . htmlspecialchars($parts[$k]) . '</strong>';
         }
     }
     // Return result:
     return implode('', $output);
 }
开发者ID:dachcom-digital,项目名称:TYPO3.CMS,代码行数:69,代码来源:SearchController.php


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