PHP/File Directory/file function
file.php
<source lang="html4strict">
<?php
$users = file("data.txt"); foreach ($users as $user) { list($name, $email) = explode(" ", $user); $email = trim($email); echo "<a href=\"mailto:$email\">$name</a>
\n"; }
?>
</source>
PHP File Logic Functions
<source lang="html4strict">
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.
</source>
Reading a File into an Array
<source lang="html4strict">
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 "Line $line_num: " . htmlspecialchars( $line ) . "
\n";
endwhile; ?>
</source>