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) The excerpt.
定义位置
  • wp-includes/formatting.php
    , line 5263
引入
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;
}