Re: When is "z" != "z" ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>Tedd,
>
>The discussion of PHP strings has been interesting; thanks for sparking that.
>
>Of course, your subject line to the contrary, it's not that "z" != "z", it's that storing an alphabetic character assumed to be a single byte in a variable and then incrementing it can result in a two-byte result.  I find it plausible that the statement $a = "a" produces a two-byte result in the first place, we just don't notice it because the second byte is turned sideways and is very, very skinny.
>
>I assume you know (but I'll state it anyway for the record) that to avoid the problems you've encountered by trying to treat apparently multi-byte PHP string variables like one-byte numerics, you can simply use numerics themselves:
>
>        for ($i = ord("a"); $i <= ord("z"); $i++)
>        {
>                echo chr($i);
>        }
>
>ord() and chr() being the PHP functions to yield the numeric value of a character and the ASCII character of a numeric value:
>http://php.net/ord & http://php.net/chr
>
>To save that hard-working server a few machine cycles, one would presumably store ord("z") in a variable before the loop began and test for that each iteration.
>
>Warm regards,
>Paul


Paul:

And I thank you for your reply -- you've been much kinder than most (on and off-list). :-)

True the subject line was a bit misleading, but that was intentional. Bait causes more fish to rise.

I've received the answer several times over since I posted the problem, but I wasn't looking for a solution because I already had one.

What I was looking for was an explanation, which I "got". I hope the answer remains with me longer than the bandages do. Asking questions in this group is like trying to feed alligators while being waist-deep in the swamp. :-)

Thanks.

tedd
-- 
------------------------------------------------------------------------------------
http://sperling.com  http://ancientstones.com  http://earthstones.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux