1.fread string fread ( int $handle , int $length ) fread() 从 handle 指向的文件中读取最多 length 个字节。该函数在读取完最多 length 个字节数,或到达 EO...
<?php $filename = "/usr/local/something.txt"; $handle = fopen($filename, "r");//读取二进制文件时,需要将第二个参数设置成'rb' //通过filesize获得文件大小,将整个文件一下子读到一个字符串中 $contents = fread($handle, filesize ($filename)); fclose($handle); ?>
<?php $handle = fopen('http://www.baidu.com', 'r'); $content = ''; while(!feof($handle)){ $content .= fread($handle, 8080); } echo $content; fclose($handle); ?>
<?php $handle = fopen('http://www.baidu.com', 'r'); $content = ''; while(false != ($a = fread($handle, 8080))){//返回false表示已经读取到文件末尾 $content .= $a; } echo $content; fclose($handle); ?>
<?php $handle = fopen('./file.txt', 'r'); while(!feof($handle)){ echo fgets($handle, 1024); } fclose($handle); ?>
<?php $handle = fopen('./file.txt', 'r'); while(!feof($handle)){ echo fgetss($handle, 1024, '<br>'); } fclose($handle); ?>
<?php $a = file('./file.txt'); foreach($a as $line => $content){ echo 'line '.($line + 1).':'.$content; } ?>
<?php $size = readfile('./file.txt'); echo $size; ?>
<?php $ctx = stream_context_create(array( 'http' => array( 'timeout' => 1 //设置超时 ) ) ); echo file_get_contents("http://www.baidu.com/", 0, $ctx); ?>
<?php header("Content-Type:text/html;charset=utf-8"); $handle = fopen('./test2.php', 'r'); fseek($handle, 1024);//将指针定位到1024字节处 fpassthru($handle); ?>