note 72472 added to ref.mbstring

From: Date: Sat, 20 Jan 2007 01:12:41 +0000
Subject: note 72472 added to ref.mbstring
Groups: php.notes 
Request: Send a blank email to php-notes+get-121944@lists.php.net to get a copy of this message
As peter dot albertsson at spray dot se already pointed out, overloading strlen may break code that handles binary data and relies upon strlen for bytelengths. The problem occurs when a file is filled with a string using fwrite in the following manner: $len = strlen($data); fwrite($fp, $data, $len); fwrite takes amount of bytes as the third parameter, but mb_strlen returns the amount of characters in the string. Since multibyte characters are possibly more than one byte in length each - this will result in that the last characters of $data never gets written to the file. After hours of investigating why PEAR::Cache_Lite didn't work - the above is what I found. I made an attempt at using single byte functions, but it doesn't work. Posting here anyway in case it helps someone else: /** * PHP Singe byte functions simulation (non successful) * * Usage: sb_string(functionname, arg1, arg2, etc); * Example: sb_string("strlen", "tuöéä"); returns 8 (should...) */ function sb_string() { $arguments = func_get_args(); $func_overloading = ini_get("mbstring.func_overload"); ini_set("mbstring.func_overload", 0); $ret = call_user_func_array(array_shift($arguments), $arguments); ini_set("mbstring.func_overload", $func_overloading); return $ret; } ---- Server IP: 129.16.214.50 Probable Submitter: 80.217.109.98 ---- Manual Page -- http://www.php.net/manual/en/ref.mbstring.php Edit -- https://master.php.net/note/edit/72472 Del: integrated -- https://master.php.net/note/delete/72472/integrated Del: useless -- https://master.php.net/note/delete/72472/useless Del: bad code -- https://master.php.net/note/delete/72472/bad+code Del: spam -- https://master.php.net/note/delete/72472/spam Del: non-english -- https://master.php.net/note/delete/72472/non-english Del: in docs -- https://master.php.net/note/delete/72472/in+docs Del: other reasons-- https://master.php.net/note/delete/72472 Reject -- https://master.php.net/note/reject/72472 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#121944) next »