函数文档

read()

💡 云策文档标注

概述

read() 函数用于从资源句柄读取指定字节数的数据,并自动推进流位置。它返回原始字节字符串或失败时返回 false。

关键要点

  • 参数 $handle 是必需的资源句柄,用于读取数据。
  • 参数 $num_bytes 是必需的正整数,指定要读取的字节数。
  • 返回值是二进制字符串或 false,表示读取成功或失败。

代码示例

function read( $handle, $num_bytes ) {
  $data = fread( $handle, $num_bytes );
  return ( $data !== false && strlen( $data ) >= $num_bytes ) ? $data : false;
}

📄 原文内容

Reads bytes and advances the stream position by the same count.

Parameters

$handleAvifinfostreamrequired
Bytes will be read from this resource.
$num_bytesintrequired
Number of bytes read. Must be greater than 0.

Return

Avifinfobinary string|false The raw bytes or false on failure.

Source

function read( $handle, $num_bytes ) {
  $data = fread( $handle, $num_bytes );
  return ( $data !== false && strlen( $data ) >= $num_bytes ) ? $data : false;
}