Usage Example of file_get_contents of Function in php

  • 2021-11-29 06:15:57
  • OfStack

Let's first look at the syntax of the file_get_contents () function in php under 1


string file_get_contents ( string $ filename , bool $ include_path = false , resource $ context , int $ offset = 0 , int $ maxlen ) 
filename is the name of the file or URL. include_path If enabled, search for files in include_path context This is a set of options for modifying the behavior of a stream offset This value specifies the starting position of the file to read. maxlen This value specifies the number of bytes to read.

Read the contents of the file as a string

This php example reads content from a file and stores it in a string variable.


<?php 
 $ content = file_get_contents (" input.txt ") ; 
 echo $ content; 
?>

Read content from URL to string


<?php
 $content = file_get_contents("http://example.com");
 echo $content;
?>

That's all about the file_get_contents () function in php. Thank you for reading and supporting this site.


Related articles: