From cba11b1ecdce8bd25a4ec6552d6e3bd29ebb0d13 Mon Sep 17 00:00:00 2001 From: dd32 Date: Fri, 2 Apr 2010 07:10:51 +0000 Subject: [PATCH] A better default except, Remove multiple white spaces from the except as well as splitting safely on UTF8 strings. Props Denis-de-Bernardy for the UTF8 split. Fixes #10376 git-svn-id: http://svn.automattic.com/wordpress/trunk@13942 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/formatting.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 0aa869652e..ac8a20f545 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -1844,11 +1844,13 @@ function wp_trim_excerpt($text) { $text = strip_tags($text); $excerpt_length = apply_filters('excerpt_length', 55); $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]'); - $words = explode(' ', $text, $excerpt_length + 1); - if (count($words) > $excerpt_length) { + $words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY); + if ( count($words) > $excerpt_length ) { array_pop($words); $text = implode(' ', $words); $text = $text . $excerpt_more; + } else { + $text = implode(' ', $words); } } return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);