Domain Empire

[Help Wanted] Minor Question for the PHP Experts

Spaceship Spaceship
Watch

theSun

Account Closed (Requested)
Impact
907
I have a php script, the bottom part goes like this:

$fh = fopen("d1.txt", "a+");
if($fh==false)
die("unable to create file");
fwrite($fh, $submit."\n");
fclose($fh);

As you see, it is simple, it basically outputs the reults in a text file and thats about it.

I would like it to outputs the result on the web browser instead of creating a file.

How would i do it? Please provide the correct code...

Thank you so much.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
I heart it is something about the echo command, so how can php code in here and provide a solution?
 
0
•••
1
•••
Try:

<?php
echo file_get_contents("d1.txt");​
?>

Thanks, that one is partially 50% done... it echos the file, but instead of making the file, i would like it to not create the file, and simply just echo the results into the browser in real time... and preferably with a new line for each result...
 
0
•••
Try the following:

PHP:
$fh = fopen('d1.txt', 'a+');

if ($fh == false)
{
    die('Unable to open file');
}

while (!feof($fh))
{
    echo fgets($fh) . "\n";
}

fclose($fh);
 
1
•••
Try the following:

PHP:
$fh = fopen('d1.txt', 'a+');

if ($fh == false)
{
    die('Unable to open file');
}

while (!feof($fh))
{
    echo fgets($fh) . "\n";
}

fclose($fh);

Thanks, very close now, as now it creates an empty file d1.txt, with no results, and nothing to echo... (as i seems to understand abit...)
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back