[svn r21274] FS#306 - The multi-byte string library: Adding a function that calculates correctly length of binary data (as number of bytes) regardless the PHP configuration (See the ini-setting mbstring.func_overload). This function may be upgraded for PHP6 in the future.

skala
Ivan Tcholakov 16 years ago
parent 2346de5a39
commit 6cf51a738c
  1. 26
      main/inc/lib/multibyte_string_functions.lib.php

@ -39,6 +39,32 @@
* be activated too.
*/
/**
* ----------------------------------------------------------------------------
* A safe way to calculate binary lenght of a string (as number of bytes)
* ----------------------------------------------------------------------------
*/
/**
* Calculates binary lenght of a string, as number of bytes, regardless the php-setting mbstring.func_overload.
* This function should work for all multi-byte related changes of PHP5 configuration.
* @param string $string The input string.
* @return int Returns the length of the input string (or binary data) as number of bytes.
*/
function api_byte_count($string) {
static $use_mb_strlen;
if (!isset($use_mb_strlen)) {
$use_mb_strlen = function_exists('mb_strlen') && ((int) ini_get('mbstring.func_overload') & 2);
}
if ($use_mb_strlen) {
return mb_strlen($string, '8bit');
}
return strlen($string);
// For PHP6 this function probably will contain:
//return strlen((binary)$string);
}
/**
* ----------------------------------------------------------------------------
* Multibyte string conversion functions

Loading…
Cancel
Save