Re: Strange string stuff -- maybe everything is ending...
| From: | Nathan Nobbe | Date: | Sat, 22 Dec 2012 00:59:24 +0000 |
| Subject: | Re: Strange string stuff -- maybe everything is ending... | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-319933@lists.php.net to get a copy of this message | ||
On Fri, Dec 21, 2012 at 4:10 PM, Nathan Nobbe <quickshiftin@gmail.com>wrote:
>
>
> On Fri, Dec 21, 2012 at 3:27 PM, Jim Giner <jim.giner@albanyhandball.com>wrote:
>
>> On 12/21/2012 5:16 PM, Tedd Sperling wrote:
>>
>>> On Dec 21, 2012, at 4:58 PM, Jim Giner <jim.giner@albanyhandball.com>
>>> wrote:
>>>
>>>>
>>>>> Never realized that you could address a string as an array of chars,
>>>> which you are doing. Could that be the issue? Or did I learn something
>>>> new? Or should you have used substr to remove that last char?
>>>>
>>>
>>> Jim:
>>>
>>> I guess you learned something new -- that's good.
>>>
>>> A string is just a "string" of chars.
>>>
>>> As such, if you define:
>>>
>>> $a = "tedd";
>>>
>>> then:
>>>
>>> $a[0] is 't';
>>> $a[1] is 'e'
>>> $a[2] is 'd'
>>> $a[3] is 'd'
>>>
>>> The only confusing thing here is the length of the string -- in this
>>> case the length of this string is four, but $a[4] has not been defined.
>>>
>>> Cheers,
>>>
>>> tedd
>>>
>>> _____________________
>>> tedd@sperling.com
>>> http://sperling.com
>>>
>>>
>>>
>>> From what I do know, there shouldn't be an a[4].
>> In any case, let's assume that there is a bug in the string logic that
>> you're using. Why not just use substr?
>>
>> $topic = substr($topic,0,-1);
>>
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
> Neat idea Tedd, but judging by a quick test, I don't think changing the
> value of the string is entirely supported though that notation.
>
> php > $str = 'blah';
> php > $str[3] = '';
> php > echo $str . PHP_EOL;
> bla
> php > echo strlen($str);
> 4
>
>
Another interesting twist along the same lines, seems the string offsets
are indeed read only:
php > unset($str[3]);
Fatal error: Cannot unset string offsets in php shell code on line 1
Call Stack:
6665.6475 384568 1. {main}() php shell code:0
-nathan