#43950 [NEW]: Char-wise v byte-wise string indexing

From: Date: Sun, 27 Jan 2008 23:17:35 +0000
Subject: #43950 [NEW]: Char-wise v byte-wise string indexing
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-121587@lists.php.net to get a copy of this message
From: jrf_temp_2003 at comcast dot net Operating system: Linux PHP version: 5.2.5 PHP Bug Type: Feature/Change Request Bug description: Char-wise v byte-wise string indexing Description: ------------ When I "upgraded" to multibyte char encoding and functions, I discovered that I could no longer rely on $s{strlen($s)-1} to access the last character in a string. Strlen correctly counted only whole chars, but the indexing came up short by the number of double-wide chars in the string and hit the wrong char. I could (and did) patch my scripts with rtrim, but others may not be so lucky. I had an idea... Suggestion: Some time ago, square brackets were deprecated in favor of curly braces for individual char access in a string. Could both be employed, each for a different purpose? Could curly braces to be used for multibyte-sensitive indexing? Could square brackets, as always, offer simple byte-wise access? Reproduce code: --------------- // After a loop chains field names + commas... $sql{strlen($sql)-1} = ' '; // Replace last trailing comma with a space $sql.= $where_clause; // Because my aim was at the very end of a string, rtrim could solve // my problem. Less specialized cases would not be so easy. Expected result: ---------------- // There should be two chars in quotes and no comma between the quoted // value and WHERE ... x="**" WHERE ... Actual result: -------------- // Two mb chars elsewhere in string displaced the substitution // by two places to the left, wiping out a quoted char and leaving // the comma: ... x="* ",WHERE ... // Could it be possible for $s{} to index by mb chars? If so, then // $s[] could be resurrected to index by bytes as both do currently. -- Edit bug report at http://bugs.php.net/?id=43950&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=43950&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=43950&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=43950&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=43950&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=43950&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=43950&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=43950&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=43950&r=needscript Try newer version: http://bugs.php.net/fix.php?id=43950&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=43950&r=support Expected behavior: http://bugs.php.net/fix.php?id=43950&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=43950&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=43950&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=43950&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43950&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=43950&r=dst IIS Stability: http://bugs.php.net/fix.php?id=43950&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=43950&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=43950&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=43950&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=43950&r=mysqlcfg

« previous php.bugs (#121587) next »