Tag Archives: Functions

fstat

It returns information about a file using an open file pointer

Example

<?php

$fp = fopen(‘test.txt’, ‘r’);

$stats = fstat($fp);

echo “<pre>”;

print_r($stats);

?>

Output

Array
(
[0] => 2049
[1] => 673768
[2] => 33279
[3] => 1
[4] => 1000
[5] => 1000
[6] => 0
[7] => 8
[8] => 1336732795
[9] => 1336732794
[10] => 1336732794
[11] => 4096
[12] => 8
[dev] => 2049
[ino] => 673768
[mode] => 33279
[nlink] => 1
[uid] => 1000
[gid] => 1000
[rdev] => 0
[size] => 8
[atime] => 1336732795
[mtime] => 1336732794
[ctime] => 1336732794
[blksize] => 4096
[blocks] => 8
)

fscanf

It parses input from a file according to a format

Example

<?php

$fp = fopen(“test.txt”, “r”);

while ($data = fscanf($fp, “%tn%sn”)) {

list ($name, $profession, $countrycode) = $data;

}

fclose($fp);

?>

fputcsv

It format line as CSV and write to file pointer

Example

<?php

$data = array ( array(‘php’, ‘asp’, ‘jsp’, ‘js’));

$fp = fopen(‘test.csv’, ‘w’);

foreach ($data as $value) {

fputcsv($fp, $value);

}

fclose($fp);

?>

fpassthru

The fpassthru() function reads all data from the current position in an open file, until EOF, and writes the result to the output buffer.

This function returns the number of characters passed or FALSE on failure.

Example

<?php

$fp = @fopen(“test.txt”, “r”);

fpassthru($fp);

?>