什么是PHP for C#ReadBytes(流长度)?

时间:2010-06-18 14:09:41

标签: c# php byte

什么是PHP for C#(假设我们打开一些本地(在服务器上)而不是OpenFileDialog

        private const int HEADER_LENGTH = 13;
        stream = File.OpenRead(openFileDialog.FileName);
        header = ReadBytes(stream, HEADER_LENGTH);

我们能否在PHP中做这样的事情作为下一步

    private const byte SIGNATURE1 = 0x46;
    private const byte SIGNATURE2 = 0x4C;
    private const byte SIGNATURE3 = 0x56;
      if ((SIGNATURE1 != header[0]) || (SIGNATURE2 != header[1]) || (SIGNATURE3 != header[2]))
            throw new InvalidDataException("Not a valid FLV file!.");

2 个答案:

答案 0 :(得分:1)

嗯,我想你会找那样的东西

$handle = fopen(FILE, 'r');
if ($handle)
{
    $head = fread ( $handle , 13 );
    if ($head[0] != chr (0x46)) ...
    ...
}

当然你可以为这个签名创建常量,但这样:

define('SIG1', chr(0x46));

然后您可以正常使用它们:$head[0] == SIG1等。您可以在定义常量时使用函数,包括常量名称和值。

答案 1 :(得分:0)

使用fopenfread

$fh = fopen($filename, "r");
if ($fh) {
    $data = fread($fh, 13);
}

PHP支持字符串上的[] -operator,因此您将能够以与在C#中基本相同的方式验证签名。