Changeset 10355
- Timestamp:
- 01/13/2009 03:18:37 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/formatting.php
r10339 r10355 208 208 } 209 209 210 // Don't bother if there are no specialchars - saves some processing 211 if ( !preg_match( '/[&<>"\']/', $string ) ) { 212 return $string; 213 } 214 215 // Store the site charset as a static to avoid multiple calls to wp_load_alloptions() 210 216 if ( !$charset ) { 211 $alloptions = wp_load_alloptions(); 212 $charset = isset( $alloptions['blog_charset'] ) ? $alloptions['blog_charset'] : ''; 217 static $_charset; 218 if ( !isset( $_charset ) ) { 219 $alloptions = wp_load_alloptions(); 220 $_charset = isset( $alloptions['blog_charset'] ) ? $alloptions['blog_charset'] : ''; 221 } 222 $charset = $_charset; 213 223 } 214 224 if ( in_array( $charset, array( 'utf8', 'utf-8', 'UTF8' ) ) ) { … … 284 294 } 285 295 296 // Don't bother if there are no entities - saves a lot of processing 297 if ( strpos( $string, '&' ) === false ) { 298 return $string; 299 } 300 286 301 // More complete than get_html_translation_table( HTML_SPECIALCHARS ) 287 302 $single = array( ''' => '\'', ''' => '\'' ); … … 341 356 } 342 357 343 if ( !in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) ) { 358 // Store the site charset as a static to avoid multiple calls to get_option() 359 static $is_utf8; 360 if ( !isset( $is_utf8 ) ) { 361 $is_utf8 = in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ); 362 } 363 if ( !$is_utf8 ) { 344 364 return $string; 345 365 } 346 366 367 // Check for support for utf8 in the installed PCRE library once and store the result in a static 368 static $utf8_pcre; 369 if ( !isset( $utf8_pcre ) ) { 370 $utf8_pcre = @preg_match( '/^./u', 'a' ); 371 } 372 // We can't demand utf8 in the PCRE installation, so just return the string in those cases 373 if ( !$utf8_pcre ) { 374 return $string; 375 } 376 347 377 // preg_match fails when it encounters invalid UTF8 in $string 348 if ( 1 === @preg_match( ' @^.@us', $string ) ) {378 if ( 1 === @preg_match( '/^./us', $string ) ) { 349 379 return $string; 350 380 } 351 381 382 // Attempt to strip the bad chars if requested (not recommended) 352 383 if ( $strip && function_exists( 'iconv' ) ) { 353 384 return iconv( 'utf-8', 'utf-8', $string ); 354 } else {355 return ''; 356 }385 } 386 387 return ''; 357 388 } 358 389
Note: See TracChangeset
for help on using the changeset viewer.