url_shorten()
url_shorten( string $url, int $length = 35 ) 缩短URL,用作链接…
url_shorten( string $url, int $length = 35 )
缩短URL,用作链接文本。
Shorten a URL, to be used as link text.
缩短URL,用作链接文本。
Shorten a URL, to be used as link text.
目录锚点:#参数#源码
参数(Parameters)
| 参数 | 类型 | 说明 |
|---|---|---|
| $url | (string) | 要缩短的URL。 |
| $length | (int) | 缩短的URL的最大长度。默认35个字符。 |
源码(Source)
/**
* Shorten an URL, to be used as link text
*
* @since 1.2.0
*
* @param string $url
* @return string
*/
function url_shorten( $url ) {
$short_url = str_replace( array( 'http://', 'www.' ), '', $url );
$short_url = untrailingslashit( $short_url );
if ( strlen( $short_url ) > 35 )
$short_url = substr( $short_url, 0, 32 ) . '…';
return $short_url;
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 4.4.0 | wp-includes/formatting.php | 7 | 15 |
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
还没有任何评论,赶紧来占个楼吧!