Home > Backend Development > PHP Tutorial > PHP implements the method of reading and outputting other files

PHP implements the method of reading and outputting other files

墨辰丷
Release: 2023-03-29 09:30:01
Original
1605 people have browsed it

This article mainly introduces the method of reading and outputting other files in PHP. Interested friends can refer to it. I hope it will be helpful to everyone.

is as follows:

ob_start();
iconv('utf-8','gb2312',readfile('1.html')); //直接输出文本内容
echo &#39;<hr>&#39;;

$data = file_get_contents(&#39;./1.html&#39;,null,null,0,10);
var_dump($data);//输出字符串
echo &#39;<hr>&#39;;


$data = file(&#39;./1.html&#39;);
var_dump($data);//输出数组
echo &#39;<hr>&#39;;

$stream = fopen(&#39;./1.html&#39;,&#39;r&#39;);
echo stream_get_contents($stream,12);//输出字符串
echo &#39;<hr>&#39;;

//fread() 读取文件(可安全用于二进制文件) 文件系统指针,是典型地由 fopen() 创建的 resource(资源)。
$data = fopen(&#39;./1.html&#39;,&#39;rb&#39;);
$contents = fread($data,filesize(&#39;./1.html&#39;));
echo $contents;//输出字符串
Copy after login

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

phpOne file to configure WeChat jssdk

php Detailed explanation of file splitting and merging to achieve breakpoint resume transfer

php Implement WeChat development to obtain user information

The above is the detailed content of PHP implements the method of reading and outputting other files. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template