How to use PHP function file_get_contents?

Guanhui
Release: 2023-03-01 17:12:02
Original
3127 people have browsed it

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;
?>
Copy after login
<?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);
?>
Copy after login
<?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"
Copy after login

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!

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