当前位置: 移动技术网 > IT编程>开发语言>PHP > php中file_get_contents()函数用法实例

php中file_get_contents()函数用法实例

2019年03月19日  | 移动技术网IT编程  | 我要评论

我们先来看一下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;
?>

以上就是关于php中file_get_contents()函数的相关知识点,感谢大家的阅读和对移动技术网的支持。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网