本文整理汇总了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;
}
示例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, '---'));
}
示例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;
}
示例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) {
示例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;
}
示例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;
}