Reading from a file
<?php
    $file = fopen("sample.txt", "r");
    while (!feof($file)) {
        echo fgets($file), "<BR>";
    }
?>
Reading from a URL
<?php $file = fopen("http://www.php.net/file.txt", "r"); ?>
Writing to a file
<?php
    $file = fopen("agent.log", "a");
    fputs($file, $HTTP_USER_AGENT."\n");
?>
Writing to a file Simplified (PHP5)
<?php
    file_put_contents("agent.log", $HTTP_USER_AGENT, FILE_APPEND);
?>