wp_html_excerpt
函数
wp_html_excerpt ( $str, $count, $more = null )
- 参数
-
-
(string)
$str
String to get the excerpt from.- Required: 是
-
(int)
$count
Maximum number of characters to take.- Required: 是
-
(string)
$more
Optional. What to append if $str needs to be trimmed. Defaults to empty string.- Required: 否
- Default: null
-
(string)
- 返回值
-
- (string) The excerpt.
- 定义位置
-
-
wp-includes/formatting.php
, line 5263
-
wp-includes/formatting.php
- 引入
- 2.5.0
- 弃用
- –
安全地从HTML字符串中提取不超过前$count的字符。
UTF-8,标签和实体安全提取前缀。里面的实体将*NOT*被算作一个字符。例如,&会被算作4,
function wp_html_excerpt( $str, $count, $more = null ) { if ( null === $more ) { $more = ''; } $str = wp_strip_all_tags( $str, true ); $excerpt = mb_substr( $str, 0, $count ); // Remove part of an entity at the end. $excerpt = preg_replace( '/&[^;s]{0,6}$/', '', $excerpt ); if ( $str != $excerpt ) { $excerpt = trim( $excerpt ) . $more; } return $excerpt; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。