note 54906 added to function.strlen

From: Date: Tue, 19 Jul 2005 12:08:45 +0000
Subject: note 54906 added to function.strlen
Groups: php.notes 
Request: Send a blank email to php-notes+get-92160@lists.php.net to get a copy of this message
> 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): $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 ---- Manual Page -- http://www.php.net/manual/en/function.strlen.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54906 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54906&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54906&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54906&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54906&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54906&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54906&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54906&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#92160) next »