How To Read the Entire File into a Single String PHP ?

Discussion in 'Website Development & Design' started by beingchinmay, Aug 22, 2015.

  1. beingchinmay

    beingchinmay
    uix_expand uix_collapse
    New Member

    Joined:
    Aug 4, 2015
    Messages:
    10
    Likes Received:
    1
    If you have a file, and you want to read the entire file into a single string, you can use the file_get_contents() function. It opens the specified file, reads all characters in the file, and returns them in a single string. Here is a PHP script example on how to file_get_contents():

     
  2. Alan Ron

    Alan Ron
    uix_expand uix_collapse
    Member

    Joined:
    Jul 29, 2015
    Messages:
    83
    Likes Received:
    7
    If you have a file, and you want to read the entire file into a single string. You can use the file_get_contents() function.

    It opens the specified file, reads all characters in the file, and returns them in a single string.

    Simple PHP Example:

    <?php

    $file = file_get_contents("-------------------------------"); ------>>>>> Source of the file

    print("Size of the file: ".strlen($file)."\n");

    ?>

    This command will return a value with no of characters in particular file for example 10,000 .
     

Share This Page