Changeset 36020
- Timestamp:
- 12/19/2015 04:58:59 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/compat.php
r36019 r36020 169 169 } 170 170 171 // The solution below works only for UTF-8, 172 // so in case of a different charset just use built-in strlen() 171 /* 172 * The solution below works only for UTF-8, so in case of a different charset 173 * just use built-in strlen(). 174 */ 173 175 if ( ! in_array( $encoding, array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) ) { 174 176 return strlen( $str ); … … 176 178 177 179 if ( _wp_can_use_pcre_u() ) { 178 // Use the regex unicode support to separate the UTF-8 characters into an array 180 // Use the regex unicode support to separate the UTF-8 characters into an array. 179 181 preg_match_all( '/./us', $str, $match ); 180 182 return count( $match[0] ); … … 193 195 )/x'; 194 196 195 $count = 1; // Start at 1 instead of 0 since the first thing we do is decrement 197 // Start at 1 instead of 0 since the first thing we do is decrement. 198 $count = 1; 196 199 do { 197 200 // We had some string left over from the last round, but we counted it in that last round. 198 201 $count--; 199 202 200 // Split by UTF-8 character, limit to 1000 characters (last array element will contain the rest of the string) 203 /* 204 * Split by UTF-8 character, limit to 1000 characters (last array element will contain 205 * the rest of the string). 206 */ 201 207 $pieces = preg_split( $regex, $str, 1000 ); 202 208 203 // Increment 209 // Increment. 204 210 $count += count( $pieces ); 205 } while ( $str = array_pop( $pieces ) ); // If there's anything left over, repeat the loop. 206 207 // Fencepost: preg_split() always returns one extra item in the array 211 212 // If there's anything left over, repeat the loop. 213 } while ( $str = array_pop( $pieces ) ); 214 215 // Fencepost: preg_split() always returns one extra item in the array. 208 216 return --$count; 209 217 }
Note: See TracChangeset
for help on using the changeset viewer.