| 
	
 | 
 Posted by Gary L. Burnore on 10/17/07 21:42 
On Wed, 17 Oct 2007 16:33:26 -0500, "Bint" <bint@csgs.com> wrote: 
 
[top posting corrected - please don't top post] 
> 
> 
>"Lars Eighner" <usenet@larseighner.com> wrote in message  
>news:slrnfhcucm.157i.usenet@debranded.larseighner.com... 
>> In our last episode, 
>> <13hcrsv3c5a2584@corp.supernews.com>, 
>> the lovely and talented Bint 
>> broadcast on comp.lang.php: 
>> 
>>> Yeah, I guess I'm trying to do something low-level with this high-level 
>>> lanugage.  I'm new to PHP so I'm trying to figure out how these fancy 
>>> keyword-based arrays work with old-school byte arrays. 
>> 
>>> I'm sending images wirelessly to a php script.  The image, originally a  
>>> grid 
>>> of pixels, each 16-bits deep, is run-length-encoded into a smaller C  
>>> array 
>>> of unsigned shorts (16 bit words).  That C array is base64 encoded into  
>>> an 
>>> ASCII string so that I can send it via HTTP POST command to a PHP script. 
>> 
>>> The PHP script sees my base64 encoded array as a variable, which I can 
>>> easily base64 decode into a php "array".  But it is proving trickier to 
>>> access my pixel values, because now the array is not a C array, but a PHP 
>>> one.  If I look at the value of array[0], then I don't get the number  
>>> that 
>>> was in array[0] before I sent it. 
>> 
>>> I can work around it, by accessing each byte of the PHP array: 
>> 
>>> $myoriginalarray[0] = ord($phparray[0]) + ord($phparray[1]) << 8; 
>> 
>>> But that is complicated and I just thought there might be some simpler  
>>> way 
>>> of telling PHP "hey, I have an array of unsigned shorts here". 
>>> Maybe not. 
>> 
>> Treat them as a string, use the base 64 decode function which takes a  
>> string 
>> argument and returns a string result.  In many respects strings are a kind 
>> of array, but they are not type array in PHP.  Conveniently, strings are 
>> composed of characters, and characters bear more than a passing  
>> resemblance 
>> to 8-bit unsigned integers.  Take them two at time if you have to  
>> manipulate 
>> them at the 16-bit level.  See chapter 11 (Types) in the manual for hints  
>> as 
>> to how to work with strings.  Don't use curly brackets, they will be 
>> deprecated in PHP 6, or so the scuttlebutt goes. 
>> 
>> Do not be confused by PHP array type. Although strings are kind of like 
>> arrays with integer indices, there are significant differences.  You  
>> should 
>> be learning to use strings from the documentation on type string, and the 
>> documentation on type array is likely to mislead you. 
 
 
>Well, let me ask you.  I've got the code working now, using the method I  
>described above.  But just for my edification, how do I know if I am working  
>with strings or arrays? 
 
A string is an array and an array is an array.  
 
 
> 
>The thing begins as a POST incoming variable, say $image. 
>Then if I start accessing elements of it, ie $image[0], $image[1], etc, then  
>am I accessing string elements? 
 
Yes, if the value in $image is a string. 
 
>And if I make a *new* entity, say $output, and start saying things like  
>$output[0] = ord($image[0]) + (ord($image[1])<<8),  then am I creating a  
>string there, or an array? 
 
Yes. 
 
 
Here, read this:  http://us.php.net/manual/en/language.types.array.php 
 
--  
gburnore at DataBasix dot Com  
--------------------------------------------------------------------------- 
                    How you look depends on where you go. 
--------------------------------------------------------------------------- 
Gary L. Burnore                       |  ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³ 
                                      |  ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³ 
Official .sig, Accept no substitutes. |  ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³ 
                                      |  ÝÛ 0 1 7 2 3 / Ý³Þ 3 7 4 9 3 0 Û³ 
Black Helicopter Repair Services, Ltd.|     Official Proof of Purchase 
===========================================================================
 
  
Navigation:
[Reply to this message] 
 |