在PHP中等效的C#byte []? [关闭]

What is the equivalent of c#'s

byte[] buffer = File.ReadAllBytes(openFileDialog1.FileName);           

in php?

Should I use file_read_contents(file) and then unpack the string into byte array?

I have zero experience in C# but I think what you're looking for is something like this

<?php
$file = fopen("file.txt","r");

while (! feof ($file))
   echo fgetc($file);

fclose($file);

Your answer isn't very clear, I think you mean reading file as an array of bytes. You can use unpack() function for this purpose:

$filename = "myFile.txt";
$handle = fopen($filename, "rb"); 
$fsize = filesize($filename); 
$contents = fread($handle, $fsize); 
$byteArray = unpack("N*",$contents); 
print_r($byteArray); 
for($n = 0; $n < 16; $n++)
{ 
   echo $byteArray [$n].'<br/>'; 
}

otherwise you can get at the individual bytes similar to how you would in C:

$data = file_get_contents("myFile.txt");
for($i = 0; $i < strlen($data); ++$i) {
$char = $data[$i];
echo "Byte $i: $char
";
}