Changeset 20859
- Timestamp:
- 05/23/2012 09:04:35 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/formatting.php
r20687 r20859 2128 2128 * Trims text to a certain number of words. 2129 2129 * 2130 * This function is localized. For languages that count 'words' by the individual 2131 * character (such as East Asian languages), the $num_words argument will apply 2132 * to the number of individual characters. 2133 * 2130 2134 * @since 3.3.0 2131 2135 * … … 2140 2144 $original_text = $text; 2141 2145 $text = wp_strip_all_tags( $text ); 2142 $words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY ); 2146 /* translators: If your word count is based on single characters (East Asian characters), 2147 enter 'characters'. Otherwise, enter 'words'. Do not translate into your own language. */ 2148 if ( 'characters' == _x( 'words', 'word count: words or characters?' ) && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) { 2149 $text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' ); 2150 preg_match_all( '/./u', $text, $words_array ); 2151 $words_array = array_slice( $words_array[0], 0, $num_words + 1 ); 2152 $sep = ''; 2153 } else { 2154 $words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY ); 2155 $sep = ' '; 2156 } 2143 2157 if ( count( $words_array ) > $num_words ) { 2144 2158 array_pop( $words_array ); 2145 $text = implode( ' ', $words_array );2159 $text = implode( $sep, $words_array ); 2146 2160 $text = $text . $more; 2147 2161 } else { 2148 $text = implode( ' ', $words_array );2162 $text = implode( $sep, $words_array ); 2149 2163 } 2150 2164 return apply_filters( 'wp_trim_words', $text, $num_words, $more, $original_text );
Note: See TracChangeset
for help on using the changeset viewer.