PHP by Example by Alex Vasilev

PHP by Example by Alex Vasilev

Author:Alex Vasilev
Language: eng
Format: epub
ISBN: 9798868802584
Publisher: Apress


Listing 6-10 shows how to write into a file in the program.<?php

// The full path to the file:

$path="D:/books/php/mytext.txt";

// We open the file for writing:

$h=fopen($path,"wt");

echo "Writing into the file.
";

echo "Enter text. To terminate, enter exit:
";

// The variable to count lines:

$k=1;

// Reads the string entered by the user:

$line=trim(fgets(STDIN));

while($line!=="exit"){

// Writes the line number into the file:

fwrite($h,"[$k] ");

// Writes the line into the file:

fwrite($h,$line."
");

// The new value for the counter:

$k++;

// Reads a new string:

$line=trim(fgets(STDIN));

}

// Closes the file:

fclose($h);

echo "The program is over.";

?>



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.