php binary?

05/04/2014 23:06 Wolfy.#1
Can you write to a binary file with php, i don't understand too much php but in c# lets say it goes BinaryWriter BW = new etc... And then you write to a file lets say BW.This write etc... Can you do that with php?
05/05/2014 21:42 Mikesch01#2
Hi,

I don't think you can do that because PHP is an interpreter language and C# is a compiler language. These are 2 different things.

There are very less operation which work in PHP for binary changes, like bitwise-OR or bitwise-AND.

What do you want to do exactly?
05/05/2014 22:35 dryPants#3
Quote:
Originally Posted by Mikesch01 View Post
Hi,

I don't think you can do that because PHP is an interpreter language and C# is a compiler language. These are 2 different things.

There are very less operation which work in PHP for binary changes, like bitwise-OR or bitwise-AND.

What do you want to do exactly?
With Ruby i can also write to binary files even it's a interpreted language ;)
But I also think PHP can't do this but well, I'm far away from being an PHP expert.
05/05/2014 23:38 Luôô#4
Maybe this ?
[Only registered and activated users can see links. Click Here To Register...]
05/06/2014 00:48 Wolfy.#5
Let me tell you what i want: in c# we have this:

Code:
            FileStream FS = new FileStream(@"path" + Name + ".usr", FileMode.CreateNew);
                BinaryWriter BW = new BinaryWriter(FS);
                BW.Write(Password);
                BW.Write(Status);
So, it writes to a file like this, this is what i get on notepad:


No idea how you will see it...
Well is there a function in php that can make files same like this?
05/06/2014 01:27 Mikesch01#6
Now it's more clearly.

Yes there are some file-handling functions in PHP.

These are the main file functions:
fopen
fwrite
fread
fclose

Tutorial: [Only registered and activated users can see links. Click Here To Register...]

You can also check out the file_put_contents function which Luôô already have written.

[Only registered and activated users can see links. Click Here To Register...]
05/06/2014 09:46 Wolfy.#7
After searching a bit i found out that the file is normal and there are only this:

[Only registered and activated users can see links. Click Here To Register...]

That tntntn is the password, someone knows how to add those control characters or how they are named with php?

Edit: I made it with this works now thank you all for your help.

Code:
<?php
$file = 'people.usr';

$current = chr(3);
$current .= "ebago";
$current .= chr(0);
file_put_contents($file, $current);
?>