|
-
May 13th, 2008, 05:14 PM
#1
Thread Starter
Frenzied Member
byte arrays?
I was wonder how do byte arrays work in php? Can anyone give me a simple example of getting the bytes of an online file then reading and writing the first few bytes? or something, please.
-
May 15th, 2008, 01:26 PM
#2
Re: byte arrays?
PHP deals with file data as strings. That does not however mean that you cannot access the byte values, because a string is an array of bytes. You can read a specific number of bytes using the fread/fwrite function with the file open binary, read or write mode.
You can then convert the string to an array of characters using the str_split function.
PHP Code:
$hwnd = fopen('/path/to/file', 'rb');
$data = fread($hwnd, 1024); $data = str_split($data);
-
May 15th, 2008, 02:46 PM
#3
Thread Starter
Frenzied Member
Re: byte arrays?
I saw something like
$str{10} to access the 10th character. Does that work too?
-
May 15th, 2008, 04:49 PM
#4
-
May 16th, 2008, 07:53 PM
#5
Re: byte arrays?
Yes, but that is the eleventh character, not the tenth.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|