Jump to content

Printing Contents of a File


nerd_energy

Recommended Posts

OS - XP, PHP 4, 5 Objective: To write the contents of about.txt to the web page.

I copied this from a PHP book and this is not working.  The book states that the function fpassthru will print the contents.  I also tried to replace this function with readfile function.  With both pieces of code, there was no error; just empty webpage
<?
$fh = fopen("about.txt" , "r");
if (!$fh)
{
die("Failed to open file <b>about.txt</b>.");
}
$s = fread($fh, 256);
fpassthru($s);
fclose($fh);
?>

Here is my third try with another PHP Programmers help.  We tried  to dump the contents into an array using function FILE.  However, the funny or not funny thing is in my editor FILE doesn't turn color to tell me it's a function.

<?php
$file = file($filename);
?>
<html>
<body>
<?php
foreach($file as $row){
echo $row;
}
?>
</body>
</html>

Is it possible to write to a web page?  I have tried other variations; even using echo. 
Thank you
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.