• Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

PHP Read file Content into String – file_get_contents() Function

Written by Rahul, Updated on September 11, 2016
PHP file_get_content, PHP, php function

PHP file_get_contents() function is used for reading the file contents into a string. This function is also capable to read content from url.

1. filename is the name of file or url.
2. include_path if enabled, Search for the file in the include_path as well
3. context this is set of options to modify the behavior of a stream
4. offset this value specifies starting position of file to read.
5. maxlen this value specifies number of bytes to read.

Syntax

PHP file_get_contents() function uses following syntax.

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

Read File Content to String

This php example script will read content from file and store into string variable.

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

Read Content from URL to String

This php example script will read content from url and store into string variable.

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

Share it!
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

Related Posts

  • How to Install Apache with PHP-FPM on CentOS 8

    December 1, 2019
  • How To Install LAMP (Apache, MySQL, PHP) on Debian 10

    November 24, 2019
  • How to Install PHP 7.4, 7.3 & 7.2 on CentOS 8

    November 17, 2019
  • How to Install Nginx with PHP-FPM on Ubuntu 18.04 LTS

    November 14, 2019
  • How to Install Apache with PHP-FPM on Ubuntu 18.04 LTS

    November 13, 2019

1 Comment

  1. Avatar Minerva Reply to Minerva
    April 20, 2019 at 12:19 am

    Great blog you’ve got here.. It’s difficult to find high-quality writing like yours
    these days. I truly appreciate individuals like you!
    Take care!!

Leave a Reply

Cancel reply

Popular Posts

  • How to Install Python 3.8 on Ubuntu, Debian and LinuxMint
  • How to Restart Network Service on CentOS 8 or RHEL 8
  • How to Check IP Address on CentOS 8
  • How to Install Java 11/8 on Amazon Linux
  • How to Configure Static IP on CentOS 8 (CLI)
Copyright © 2013-2019 TecAdmin.net. All Rights Reserved. This site uses cookies. By using this website you agree with our term and services
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkNo
Revoke cookies