PHP/File Directory/file function

Материал из Web эксперт
Перейти к: навигация, поиск

file.php

 
<?php
   $users = file("data.txt");
   foreach ($users as $user) {
      list($name, $email) = explode(" ", $user);
      $email = trim($email);
      echo "<a href=\"mailto:$email\">$name</a> <br />\n";
   }
?>



PHP File Logic Functions

 
is_dir()               Determines if the file is a directory.
 
is_executable()        Determines if the file is executable by PHP.
 
is_file()              Determines if the filename is an actual file or a symbolic link to a file (returns true if a real file).
 
is_link()              Determines if the file is a symbolic link or an actual file (opposite of is_file()).
 
is_readable()          Determines if PHP is able to read from the given file.
 
is_uploaded_file()     Determines if the given file was uploaded to the server via the Web server.
 
is_writeable()         Determines if PHP is able to write to the given file.
 
file_exists()          Determines if the given file exists.



Reading a File into an Array

 
file() function reads the entire contents of a file into an indexed array. 
Its syntax is: array file (string file [, int use_include_path])
If use_include_path is set to 1, then the file is searched along the include path in the php.ini file. 
<?
$file_array = file( "data.txt" );
while ( list( $line_num, $line ) = each( $file_array ) ) :
     print "<b>Line $line_num:</b> " . htmlspecialchars( $line ) . "<br>\n";
endwhile;
?>