wp_check_invalid_utf8 [ WordPress Function ]
wp_check_invalid_utf8 ( $string, $strip = false )
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Benzer Fonksiyonlar: wp_cache_init, wp_check_filetype_and_ext, wp_suspend_cache_invalidation, wp_check_password, wp_kses_check_attr_val
Checks for invalid UTF8 in a string.
Source
<?php
function wp_check_invalid_utf8( $string, $strip = false ) {
$string = (string) $string;
if ( 0 === strlen( $string ) ) {
return '';
}
// Store the site charset as a static to avoid multiple calls to get_option()
static $is_utf8;
if ( !isset( $is_utf8 ) ) {
$is_utf8 = in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) );
}
if ( !$is_utf8 ) {
return $string;
}
// Check for support for utf8 in the installed PCRE library once and store the result in a static
static $utf8_pcre;
if ( !isset( $utf8_pcre ) ) {
$utf8_pcre = @preg_match( '/^./u', 'a' );
}
// We can't demand utf8 in the PCRE installation, so just return the string in those cases
if ( !$utf8_pcre ) {
return $string;
}
// preg_match fails when it encounters invalid UTF8 in $string
if ( 1 === @preg_match( '/^./us', $string ) ) {
return $string;
}
// Attempt to strip the bad chars if requested (not recommended)
if ( $strip && function_exists( 'iconv' ) ) {
return iconv( 'utf-8', 'utf-8', $string );
}
return '';
}
?>
Examples [ wp-snippets.com ]
Google Arama Sonuçlarý
- #11175 (wp_check_invalid_utf8() should drop invalid utf-8 chars ...
When you call wp_check_invalid_utf8() with 2nd param set to true, it tries to strip invalid utf-8. Now it removes 1st invalid utf-8 char and all chars after it, no matter ...
core.trac.wordpress.org - wp_check_invalid_utf8
Function and Method Cross Reference. wp_check_invalid_utf8(). Defined at: /wp- includes/formatting.php -> line 500. Referenced 4 times: ...
phpxref.ftwr.co.uk - wp_check_invalid_utf8 (WordPress Function) - WPSeek.com
WordPress lookup for wp_check_invalid_utf8, a WordPress Function. wpseek. com is a WordPress-centric search tool for developers and theme authors.
wpseek.com - What is wp_check_invalid_utf8? - WordPress - Stack Exchange
May 16, 2011 ... share [g+] share [fb] share [tw]. The following function checks option, if * blog_charset* is not utf8, than return original string. What is the purpose ...
wordpress.stackexchange.com