Re: Bug with substr in RC8

From: Date: Tue, 01 May 2001 16:45:41 +0000
Subject: Re: Bug with substr in RC8
References: 1  Groups: php.qa 
Request: Send a blank email to php-qa+get-2983@lists.php.net to get a copy of this message
At 05:38 PM 5/1/2001 +0100, Liz wrote:
OK, As promised Ive been doing some testing, and it seems that by chance I found something odd.. A script such as <? $a="a"; echo "$a=a\n"; echo "length of $a=".strlen($a)."\n"; echo "first 2 characters of $a are ".substr($a,1); echo "test completed"; ?> Results in the wrong results. substr($a,1) does not result in a, in fact it results in nothing at all. (this was on linux), but on windows, I had managed (dont ask) to do substr($somestring,2,length($somestring)-6); however, of course length is the wrong function so returned 1 and so I did -5 .. but instead of moaning, my script just stopped, no errors nothing.... Is it just me?? I can drag out the src for it, it was in the middle of something obscure I was working on today..
http://www.php.net/manual/en/function.substr.php You'll see that this is the correct behavior. The first letter is 0, the second is 1 and so on. Andi

« previous php.qa (#2983) next »