Switch language
wpseek on Twitter


A WordPress-centric search engine for devs and theme authors




wp_html_excerpt [ ]

wp_html_excerpt ( $str, $count, $more = null )
Parameters:
  • (string) $str String to get the excerpt from.
  • (integer) $count Maximum number of characters to take.
  • (string) $more Optional. What to append if $str needs to be trimmed. Defaults to empty string.
Returns:
  • (string) The excerpt.
Defined at:
Codex



Safely extracts not more than the first $count characters from html string.

UTF-8, tags and entities safe prefix extraction. Entities inside will NOT be counted as one character. For example & will be counted as 4, < as 3, etc.

Source

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;
}

Top Google Search Results

User Note(s)