Skip to content

Instantly share code, notes, and snippets.

@Nutrox
Created January 5, 2011 00:25
Show Gist options
  • Save Nutrox/765710 to your computer and use it in GitHub Desktop.
Save Nutrox/765710 to your computer and use it in GitHub Desktop.
PHP - Counts the number of bytes in a string, regardless of any mbstring overloading.
// Counts the number of bytes in a string.
function count_bytes( &$str ) {
if( ini_get( 'mbstring.func_overload' ) ) {
return mb_strlen( $str, '8bit' );
}
// Ideally we want strlen() to be used, because it's fast.
return strlen( $str );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment