Home  >  Article  >  Backend Development  >  How to read file contents into a string using file_get_contents() function in php

How to read file contents into a string using file_get_contents() function in php

不言
不言Original
2019-02-21 10:26:513939browse

The file_get_contents() function in How to read file contents into a string using file_get_contents() function in php is used to read file contents into a string. This function can also read content from the URL. Let's take a closer look at how the file_get_contents() function in PHP reads the file content into a string.

How to read file contents into a string using file_get_contents() function in php

Let’s first look at the syntax of the file_get_contents() function in How to read file contents into a string using file_get_contents() function in php

string file_get_contents(string $ filename,bool $ include_path = false,resource $ context,int $ offset = 0,int $ maxlen)

filename is a file or URL The name.

include_path If enabled, files are searched for in include_path

context This is the set of options used to modify the behavior of the stream

offset This value specifies the offset of the file to read starting point.

maxlen This value specifies the number of bytes to read.

Read file content as string

This How to read file contents into a string using file_get_contents() function in php example will read the content from a file and store it into a string variable.

<?How to read file contents into a string using file_get_contents() function in php 
  $ content = file_get_contents(“input.txt”); 
  echo $ content; 
?>

Read content from URL to string

<?How to read file contents into a string using file_get_contents() function in php
  $content =  file_get_contents("http://example.com");
  echo $content;
?>

This article is over here. For more exciting content, you can follow How to read file contents into a string using file_get_contents() function in php Chinese website Other related column tutorials! ! !

The above is the detailed content of How to read file contents into a string using file_get_contents() function in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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