ID: 12274 Comment by: magazine-analsex730 at hotmail dot com Reported By: tegel at dubaron dot com Status: Bogus Bug Type: Strings related Operating System: NT4 PHP Version: 4.0.4pl1 New Comment:
<a href=http://18black-pregnant-an.da.ru>analsex magazine</a> Previous Comments: ------------------------------------------------------------------------ [2001-07-21 04:29:55] tegel at dubaron dot com Output with second version of function: �ITO d.o.o. Osijek Output with first version of function: Warning: Undefined offset: 1 in c:\inetpub\wwwroot\info.php on line 20 Warning: Undefined offset: 2 in c:\inetpub\wwwroot\info.php on line 20 etc. etc. Elements $t[1]..$t[n] are _lost_ ! changing function to start from element $t[1] (skip first character) like "for ($i=1; $i<n; $i++)" and all suddenly works fine... (except for first char not get translated)... ------------------------------------------------------------------------ [2001-07-21 04:15:14] tegel at dubaron dot com This piece of code works correct with our system as well: <? $s = "hello" ; $s[0] = "H" ; var_dump($s) ; ?> Original sourcecode generating this problem is as follows (although i can not see a particular difference): function ansi2htmlsingle($t) { //convert special characters from one 8-byte //charset another for ($i=0; $i<strlen($t); $i++ ) { $c=ord($t[$i]); $d=$c; switch ($c) { case 138: $d=169; break; case 142: $d=174; break; case 154: $d=185; break; case 158: $d=190; break; }; $t[$i]=chr($d); }; return $t; }; The above function is working only not for character $t[0]. This one is: function ansi2htmlsingle($t) { $r=''; for ($i=0; $i<strlen($t); $i++ ) { $c=ord($t[$i]); $d=$c; switch ($c) { case 138: $d=169; break; case 142: $d=174; break; case 154: $d=185; break; case 158: $d=190; break; }; $r=$r.chr($d); }; return $r; }; ------------------------------------------------------------------------ [2001-07-20 22:52:51] [EMAIL PROTECTED] BTW, I can't reproduce it with a recent CVS checkout: [EMAIL PROTECTED] cynic]$ cat test.php <? $s = "hello" ; $s[0] = "H" ; var_dump($s) ; ?> [EMAIL PROTECTED] cynic]$ php -q test.php string(5) "Hello" [EMAIL PROTECTED] cynic]$ php -v 4.0.7-dev ------------------------------------------------------------------------ [2001-07-20 14:22:20] [EMAIL PROTECTED] Oops - that should be bogus, not closed. :) ------------------------------------------------------------------------ [2001-07-20 14:20:38] [EMAIL PROTECTED] The use of brackets as to access a single character from a string is deprecated. Use curly braces instead and you will experience the expected behavior. i.e. <?php $foo = 'bar'; $foo{2} = 't'; echo $foo; ?> There is additional information at http://www.php.net/manual/en/language.types.string.php ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/12274 -- Edit this bug report at http://bugs.php.net/?id=12274&edit=1
