Home  >  Article  >  Backend Development  >  How to use PHP function file_get_contents?

How to use PHP function file_get_contents?

Guanhui
GuanhuiOriginal
2020-06-24 14:02:123104browse

How to use PHP function file_get_contents?

How to use the PHP function file_get_contents?

The function of file_get_contents function in PHP is to read the entire file into a string. Its syntax is "file_get_contents($filename)". The return value is the read character. The usage method is just Just pass the file path into $filename.

Usage examples

<?php
$homepage = file_get_contents(&#39;http://www.example.com/&#39;);
echo $homepage;
?>
<?php
// <= PHP 5
$file = file_get_contents(&#39;./people.txt&#39;, true);
// > PHP 5
$file = file_get_contents(&#39;./people.txt&#39;, FILE_USE_INCLUDE_PATH);
?>
<?php
// Read 14 characters starting from the 21st character
$section = file_get_contents(&#39;./people.txt&#39;, NULL, NULL, 20, 14);
var_dump($section);
?>
string(14) "lle Bjori Ro"

Recommended tutorial: "PHP"

The above is the detailed content of How to use PHP function file_get_contents?. 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
Previous article:How to use PHP fopen?Next article:How to use PHP fopen?

Related articles

See more