file() File Read PHP Filesystem Function Example

file php filesystem function example - reads and returns entire file into an array

file-php-filesystem-function-example.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title>file php filesystem function example - reads and returns entire file into an array</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="Author" content="Md Iqbal Hosan">
  <meta name="title" content="file php filesystem function example - reads and returns entire file into an array">
  <meta name="keywords" content="php, example, code, file, function, filesystem, filestream, array">
  <meta name="description" content="file php filesystem function example - reads and returns entire file into an array">
  <style>
   h2, h4{background:orange; color:#000084;}
   h2{ padding:3px; margin:3px; font-size:21px;}
   h4{ padding:2px; margin:2px; font-size:17px;}
   p{padding:2px; margin:2px; color:#0099FC;}
   body{ background:#FFFFFA;}
  </style>
 </head>
 <body>
  <h2>file php filesystem function example - reads and returns entire file into an array</h2>
  <pre>
   <?php
    /*
     -------------------------------------------------------------------------------------------
     let say we have a file name called test.php in local server,
     we would like to read the entire file in the array format by using php basename function.
     -------------------------------------------------------------------------------------------
    */
    $filePathInDirectory = "http://127.0.0.1/phpexamplecode/test.php";
    echo "<h4>Output of filePathInDirectory in the browser</h4>";
    print "<p>$"."filePathInDirectory = {$filePathInDirectory}</p>";
    /*
     -----------------------------------------------------------
     find the basename using php filesystem basename function
     -----------------------------------------------------------
    */
    $fileInArray = array();
    $fileInArray = file($filePathInDirectory);
    echo "<h4>Output of fileInArray in the browser</h4>";
    echo "<pre>";
    print_r($fileInArray);
    echo "</pre>";
   ?>
  </pre>
 </body>
</html>

file php filesystem function example - reads and returns entire file into an array - output in the browser

 

Related Tutorial Examples

  1. HTML Form Example in PHP
  2. PHP HTML Form select box Example
  3. PHP HTML Form checkbox Example
  4. PHP HTML Form radio button Example
  5. PHP HTML Form textarea Example
  6. PHP HTML Form Input Example
  7. 19 Examples to Learn MySQL
  8. Google Maps Static API PHP Class Example
  9. 20 steps to make CakePHP Blog Project
  10. chmod() Access Permission PHP Filesystem Function Example

No comments:

Post a Comment

leave your comments here..