Staredit Network

Staredit Network -> Computers and Technical -> PHP Question
Report, edit, etc...Posted by O)FaRTy1billion on 2006-01-30 at 19:22:50
I have been thinking about making something that requires PHP. But before I get too far into anything serious, I would like to know if PHP can use binary files or binary data (non-text files/data; Ex: if you opened a sound, image, or map it would appear to be random jumbles of characters, numbers, symbols, and letters).
(I am pretty new to the PHP thing, so don't be surprised if I am entirely confused. tongue.gif)
Report, edit, etc...Posted by Shmeeps on 2006-01-30 at 19:33:23
Although I've never tried it, I would assume you could.

If nothing else, there's bound to be a library for it somewhere.
Report, edit, etc...Posted by Doodle77(MM) on 2006-01-30 at 21:01:38
PHP is binary-safe, but i'm not sure if it has int reading functions.
In some space that i think rexy had that i saw once there was something that read a bit of some CHKs. There was also a folder called "fartysux"
LOL, i think this post influenced my sig:
[attachmentid=17268]
Report, edit, etc...Posted by O)FaRTy1billion on 2006-01-31 at 18:23:27
QUOTE(Moose77 @ Jan 30 2006, 07:01 PM)
There was also a folder called "fartysux"
And I might know what is in there shifty.gif

I mostly need writing it; if it can read it that would be better.
Report, edit, etc...Posted by Shmeeps on 2006-01-31 at 18:55:03
Wait, binary or this?
Report, edit, etc...Posted by O)FaRTy1billion on 2006-02-01 at 17:34:52
"this"
Report, edit, etc...Posted by Shmeeps on 2006-02-01 at 21:03:31
Then yes, you can.
Report, edit, etc...Posted by O)FaRTy1billion on 2006-02-01 at 21:09:13
Yay!!

I shall leave this open just incase there is something more someone wants to tell me.
Report, edit, etc...Posted by Shmeeps on 2006-02-01 at 22:41:26
It seems to keep it intact too, and writing works too. Changed that file into a quick copy test and it worked fine.
Report, edit, etc...Posted by RexyRex on 2006-02-01 at 23:39:36
The "This" link just shows a bunch of scrambled ASCII letters to me. mellow.gif

However, you can to use bin2hex() on all of the data to get the output you're looking for.
Report, edit, etc...Posted by O)FaRTy1billion on 2006-02-02 at 17:47:25
QUOTE(RexyRex @ Feb 1 2006, 09:39 PM)
The "This" link just shows a bunch of scrambled ASCII letters to me. mellow.gif
That is what "binary data" is.
Report, edit, etc...Posted by Shmeeps on 2006-02-02 at 18:40:49
I updated it so it kinda tells you what it's doing.

Also, it seems to have trouble outputting a read file. Although it doesn't affect writing. I'll have to check it out some more to find a solution.
Report, edit, etc...Posted by DT_Battlekruser on 2006-02-03 at 01:11:04
Rofl, the ASCII contains <b> and <i> happy.gif
Report, edit, etc...Posted by O)FaRTy1billion on 2006-02-05 at 15:05:50
If I had some 256-color images and I wanted them to have a specific palette for different uses, could PHP add the palette or put together pieces of data and send it as an image?
Report, edit, etc...Posted by Shmeeps on 2006-02-05 at 15:33:07
It could definately send it as an image. Either using the GD library to output it, or save it and use the MAIL function to send it as an attachment or link. Either way, yes, it could do that.

As for the pallette, I don't know how you do that. If you can change it by changing the binary to get that effect, then you could use STR_REPLACE or PREG_REPLACE (str for just one string to replace, preg for patterns to replace) to change it, then save it.

It should be able to work, suppose you'd have to try it out to see though.
Report, edit, etc...Posted by O)FaRTy1billion on 2006-02-05 at 21:40:09
Say I cut the image so I have everything before the palette, the palette, and everything after the palette (and save each part as a seperate file). Could I then recombine the 3 files and send it to a browser as just a normal file?

I need the same images, but a few different parts of the palette will be different and I do not want to make multiples of the images. (1.24 mb of images * 13 ><)

Edit: Cutting up the image won't be a problem, because I sometimes will use a hexeditor as my image editor.
Report, edit, etc...Posted by Shmeeps on 2006-02-05 at 22:08:33
It's very possible. There's a function to find a string in a string and cut them into two seperate variables at the location of that string. I don't remember the function name though, you can probably find it in the PHP manual (http://www.php.net).

But after doing that, you can edit it, then use something like

$file = $piece1;
$file .= $piece2;
$file .= $piece3;

To recombine it all, then save it to a file.
Report, edit, etc...Posted by Doodle77(MM) on 2006-02-05 at 22:18:44
And then you would header('Content-Type: image/bmp');
echo $file;
Report, edit, etc...Posted by O)FaRTy1billion on 2006-02-05 at 22:37:59
What if it is a GIF (non-animated)?
Report, edit, etc...Posted by Shmeeps on 2006-02-05 at 23:00:26
CODE

header('Content-Type: image/gif');


I believe.
Report, edit, etc...Posted by RexyRex on 2006-02-06 at 02:37:51
http://www.utoronto.ca/webdocs/HTMLdocs/Bo...b/mimetype.html
Report, edit, etc...Posted by O)FaRTy1billion on 2006-02-06 at 18:39:34
Instead of just cutting up the images and saving as several files, could PHP replace specific bytes at specific locations in the file? I do not really want to cut up that many images ><

Just loading specific palettes would be easier and would not have to worry about all this. sad.gif
Report, edit, etc...Posted by Shmeeps on 2006-02-07 at 18:25:20
You could try

CODE

str_replace("$find", "$replace", $string);


Only thing is that if there's another section of it thats the same, it will replace it too.
Report, edit, etc...Posted by O)FaRTy1billion on 2006-02-07 at 19:17:46
What I need changed will always be in the same place. (Although I do not think there will be multiple of the same thing)
Report, edit, etc...Posted by Shmeeps on 2006-02-07 at 20:38:44
CODE

substr_replace($string, $replacement, $begin, $end);


$string is the binary.
$replacement is what to change it into.
$begin is first position of the string you want to replace. Count up to it.
$end is the last position to change. ($begin + $replacement).

I'm bad at explainging stuff, this might help:
http://us2.php.net/manual/en/function.substr-replace.php
Next Page (1)