|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34287 geting the first letter of a string
Submitted: 2005-08-28 14:12 UTC Modified: 2005-09-05 01:00 UTC
Avg. Score:3.5 ± 1.5
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: stuk88 at gmail dot com Assigned:
Status: No Feedback Package: MySQL related
PHP Version: 5CVS-2005-08-28 (CVS) OS: Win XP
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2005-08-28 14:12 UTC] stuk88 at gmail dot com
When i try to see the first letter of a string on php5 like 
$var{0} - it returns an empty string...
and when i use substr i need to start the string from 1 (not 0) and finish on 2 (not 1) - is it a bug or a php 5 improvment?
it seems to be a problem in all the php 5 based servers

Reproduce code:
$var = "my name is stas<br>";
echo $var{0};


$var = "my name is stas";
echo substr($var,0,1);

Expected result:

Actual result:
its showing an empty page with nothing in it
and just when i use the substr with the first letter 1 and end 2 its returns me the right thing...


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-28 16:30 UTC]
Works fine.

 [2005-08-28 18:46 UTC] stuk88 at gmail dot com
it dosent...
i used a mysql result array var and i tryed to see the first letter and it doesnt worked with {0}
and the substr($var['title'], 1, 2); (for exsamle) returned the first letter but the 
substr($var['title'], 0, 1);
 [2005-08-28 20:09 UTC]
Then provide a reproducing script that actually does NOT work for you!! The lines you provided work just fine.

 [2005-09-05 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2011-05-24 11:39 UTC] p dot hu at freemail dot hu
I just ran into a similar problem. One script returned a strange first character that was not visible in a browser when utf8 encoding was selected, but an other script that used this as an input did not work well.
I tried to convert the string, changed some settings in mysql where the result came from, but nothing helped.
After several hours of head scratchig it turned out that the script itself was written with utf8 encoding. Changing it to ansi solved the problem. (Thanks Notepad++) The result string started correctly from char[0].
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jul 20 22:01:29 2024 UTC