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.
)
Although I've never tried it, I would assume you could.
If nothing else, there's bound to be a library for it somewhere.
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]
QUOTE(Moose77 @ Jan 30 2006, 07:01 PM)
There was also a folder called "fartysux"
And I might know what is in there
I mostly need writing it; if it can read it that would be better.
Yay!!
I shall leave this open just incase there is something more someone wants to tell me.
It seems to keep it intact too, and writing works too. Changed that file into a quick copy test and it worked fine.
The "This" link just shows a bunch of scrambled ASCII letters to me.
However, you can to use bin2hex() on all of the data to get the output you're looking for.
QUOTE(RexyRex @ Feb 1 2006, 09:39 PM)
The "This" link just shows a bunch of scrambled ASCII letters to me.
That is what "binary data" is.
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.
Rofl, the ASCII contains <b> and <i> 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?
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.
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.
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.
And then you would header('Content-Type: image/bmp');
echo $file;
What if it is a GIF (non-animated)?
CODE
header('Content-Type: image/gif');
I believe.
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.
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.
What I need changed will always be in the same place. (Although I do not think there will be multiple of the same thing)
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