我们先来看一下php中的 file_get_contents()函数的语法
string file_get_contents(string $ filename,bool $ include_path = false,resource $ context,int $ offset = 0,int $ maxlen)
filename是文件或URL的称号。
include_path假如启用,则在include_path中搜刮文件
context这是用于修正流的行动的选项集
offset此值指定要读取的文件的肇端位置。
maxlen此值指定要读取的字节数。
将文件内容读取为字符串
这个php示例将从文件中读取内容并存储到字符串变量中。
<?php $ content = file_get_contents(“input.txt”); echo $ content; ?>
将内容从URL读取到字符串
<?php $content = file_get_contents("http://example.com"); echo $content; ?>
本篇文章到这里就已悉数完毕了,更多精彩内容人人能够关注ki4网的其他相干栏目教程!!!
以上就是怎样运用php中的file_get_contents()函数将文件内容读入字符串的细致内容,更多请关注ki4网别的相干文章!