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


PHP str::short方法代码示例

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


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

示例1: truncateString

function truncateString($text, $length)
{
    ob_start();
    $short = \str::short($text, $length);
    ob_end_clean();
    return $short;
}
开发者ID:aizlewood,项目名称:2016,代码行数:7,代码来源:comments.php

示例2: testShort

 public function testShort()
 {
     // too long
     $this->assertEquals('Super…', str::short($this->sample, 5));
     // not too long
     $this->assertEquals($this->sample, str::short($this->sample, 100));
     // zero chars
     $this->assertEquals($this->sample, str::short($this->sample, 0));
     // with different ellipsis character
     $this->assertEquals('Super---', str::short($this->sample, 5, '---'));
 }
开发者ID:aoimedia,项目名称:kosmonautensofa,代码行数:11,代码来源:StrTest.php

示例3: short

 /**
  * Shortens an URL
  * It removes http:// or https:// and uses str::short afterwards
  *
  * @param  string  $url The URL to be shortened
  * @param  int     $chars The final number of characters the URL should have
  * @param  boolean $base True: only take the base of the URL. 
  * @param  string  $rep The element, which should be added if the string is too long. Ellipsis is the default.
  * @return string  The shortened URL  
  */
 static function short($url, $chars = false, $base = false, $rep = '…')
 {
     $url = str_replace('http://', '', $url);
     $url = str_replace('https://', '', $url);
     $url = str_replace('ftp://', '', $url);
     $url = str_replace('www.', '', $url);
     if ($base) {
         $a = explode('/', $url);
         $url = a::get($a, 0);
     }
     return $chars ? str::short($url, $chars, $rep) : $url;
 }
开发者ID:sdvig,项目名称:kirbycms,代码行数:22,代码来源:kirby.php

示例4: function

 * @param Field $field The calling Kirby Field instance
 * @param integer $chars The desired excerpt length
 * @return string
 */
field::$methods['excerpt'] = function ($field, $chars = 140, $mode = 'chars') {
    return excerpt($field, $chars, $mode);
};
/**
 * Shortens the field value by the given length
 * @param Field $field The calling Kirby Field instance
 * @param integer $length The desired string length
 * @param string $rep The attached ellipsis character if the string is longer
 * @return string
 */
field::$methods['short'] = function ($field, $length, $rep = '…') {
    return str::short($field->value, $length, $rep);
};
/**
 * Returns the string length of the field value
 * @param Field $field The calling Kirby Field instance
 * @return integer
 */
field::$methods['length'] = function ($field) {
    return str::length($field->value);
};
/**
 * Returns the word count for the field value
 * @param Field $field The calling Kirby Field instance
 * @return integer
 */
field::$methods['words'] = function ($field) {
开发者ID:kristianhalte,项目名称:super_organic,代码行数:31,代码来源:methods.php

示例5: short

 /**
  * Shortens a URL
  * It removes http:// or https:// and uses str::short afterwards
  *
  * <code>
  *
  * echo url::short('http://veryveryverylongurl.com', 30);
  * // output: veryveryverylongurl.com
  *
  * </code>
  *
  * @param  string  $url The URL to be shortened
  * @param  int     $chars The final number of characters the URL should have
  * @param  boolean $base True: only take the base of the URL.
  * @param  string  $rep The element, which should be added if the string is too long. Ellipsis is the default.
  * @return string  The shortened URL
  */
 public static function short($url, $length = false, $base = false, $rep = '…')
 {
     if ($base) {
         $url = static::base($url);
     }
     // replace all the nasty stuff from the url
     $url = str_replace(array('http://', 'https://', 'ftp://', 'www.'), '', $url);
     // try to remove the last / after the url
     $url = rtrim($url, '/');
     return $length ? str::short($url, $length, $rep) : $url;
 }
开发者ID:LucasFyl,项目名称:korakia,代码行数:28,代码来源:url.php

示例6: short

 /**
  * Shortens an URL
  * It removes http:// or https:// and uses str::short afterwards
  *
  * @param  string  $url The URL to be shortened
  * @param  int     $chars The final number of characters the URL should have
  * @param  boolean $base True: only take the base of the URL. 
  * @param  string  $rep The element, which should be added if the string is too long. Ellipsis is the default.
  * @return string  The shortened URL  
  */
 static function short($url, $chars = false, $base = false, $rep = '…')
 {
     $url = str_replace('http://', '', $url);
     $url = str_replace('https://', '', $url);
     $url = str_replace('ftp://', '', $url);
     $url = str_replace('www.', '', $url);
     if ($base) {
         $a = explode('/', $url);
         $url = a::get($a, 0);
     }
     // try to remove the last / after the url
     $url = preg_replace('!(\\/)$!', '', $url);
     return $chars ? str::short($url, $chars, $rep) : $url;
 }
开发者ID:JaimeeKatanshin,项目名称:kirbycms,代码行数:24,代码来源:kirby.php


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