note 54906 deleted from function.strlen by cmb

From: Date: Sun, 25 Jul 2021 14:16:08 +0000
Subject: note 54906 deleted from function.strlen by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-216650@lists.php.net to get a copy of this message
Note Submitter: bartek at proteus,pl ---- > Just a precisation, maybe obvious, about the strlen() behaviour: > with binary strings (i.e. returned by the pack() finction) is made > a byte count... so strlen returns the number of bytes contained > in the binary string. This is not always true. strlen() might be shadowed by mb_strlen(). If that is the case it might treat binary data as unocode string and return wrong value (I just found it out after fighting with egroupware email attachment handling bug). So, if your data is binary I would suggest using somthing like this (parts of the code from egroupware): <?php $has_mbstring = extension_loaded('mbstring') ||@dl(PHP_SHLIB_PREFIX.'mbstring.'.PHP_SHLIB_SUFFIX); $has_mb_shadow = (int) ini_get('mbstring.func_overload'); if ($has_mbstring && ($has_mb_shadow & 2) ) { $size = mb_strlen($this->output_data,'latin1'); } else { $size = strlen($this->output_data); } ?> -- Bartek

« previous php.notes (#216650) next »