Multi-byte character safe excerpting from nbachiyski. fixes #6077
git-svn-id: http://svn.automattic.com/wordpress/trunk@7140 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -1370,4 +1370,26 @@ function wp_sprintf_l($pattern, $args) {
|
||||
return $result . substr($pattern, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely extracts not more than the first $count characters from html string
|
||||
*
|
||||
* UTF-8, tags and entities safe prefix extraction. Entities inside will be
|
||||
* counted as one character. As a side effect, all entities will be converted to
|
||||
* their decimal form.
|
||||
*
|
||||
* @param integer $str String to get the excerpt from
|
||||
* @param integer $count Maximum number of visible characters to take
|
||||
* @eaturn string the excerpt
|
||||
*/
|
||||
function wp_html_excerpt( $str, $count ) {
|
||||
$str = strip_tags( $str );
|
||||
$str = html_entity_decode( $str, ENT_QUOTES);
|
||||
$str = mb_strcut( $str, 0, $count );
|
||||
// remove part of an entity at the end
|
||||
$str = preg_replace( '/&[^;\s]{0,6}$/', '', $str );
|
||||
// we decoded some entities we should put back
|
||||
$str = wp_specialchars( $str );
|
||||
return $str;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user