php fread函数与fread函数用法
php教程 fread函数与fread函数用法
/*
fread语法:
string fread ( resource $handle , int $length )
fread()读取到的字节长度由处理引用的文件指针。读尽快停止对符合下列条件之一:
已经读取的字节长度
!eof(文件结束)达到
一包可用网络(流)
已阅读8192字节(打开后用户空间流)
*/
//fread读取文件实例一
$filename = "/www.bkjia.com/local/something.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
//php5以上版本读取远程服务器内容
$handle = fopen("http://www.bkjia.com/", "rb");
$contents = stream_get_contents($handle);
fclose($handle);
//
$handle = fopen("http://down.php100.com/", "rb");
$contents = '';
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
/*
有时流的目的不是用eof标记,也不是固定的标志,这就是为什么这个循环永远。这引起了我许多烦恼...
我解决它使用stream_get_meta_data功能,如下面显示一个break语句:
*/
$fp = fsockopen("mb.php100.com", 80);
if (!$fp) {
echo "$errstr ($errno)
n";
} else {
fwrite($fp, "data sent by socket");
$content = "";
while (!feof($fp)) {
$content .= fread($fp, 1024);
$stream_meta_data = stream_get_meta_data($fp); //added line
if($stream_meta_data['unread_bytes'] }
fclose($fp);
echo $content;
}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.