Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Php get a certain number of bytes


ranma's Avatar
Member
0 0

I want to make a program that will take a certain number of bytes from a file. I have a few questions. 1: How many bytes is a letter? 2: Are all characters (a,b,"space", $,7, &, etc…) the same amount of bytes? 3: How can I make a web page get a certain number of bytes from a file? 4: How can I make sure I don't cut off a word or something?

BTW how do you filter characters like ' " or &?

Thakns in advance!;)

Sorry for triple post!


Mr_Cheese's Avatar
0 1

every charachter is 1 byte.

also in php you can open the file and then you can specify how many bytes of teh file you wish to extract, so you can easily do that.

and there woudlnt be a easy way of making it not cut off a word, because it will read the file based on bytes instead of words. so to make it not cut off 1/2 a word etc you'll have to add a new function that checks the last byte equals a space (the if not add one byte etc), then yuo can be sure it wont cut off a word. ofcourse this will only work on text based files and wont work with exe's / jpgs etc.


ghost's Avatar
0 0

usually 1 character = 1 byte

but in the case of unicode

1 unicode character = 2 bytes


ghost's Avatar
0 0

The PHP function filesize() will return the number of bytes in the file you provide. So if you're going to read from a file and don't want t count how many bytes are in it, you can do it like this fread($fp, filesize($file));. That way you're pulling out the exact amount of bytes, no need for guess work.

http://php.net/filesize