PHP read the contents of the file and write data to the file here is the main line of writing data to a file, also a line to read the contents of the file.
PHP Tutorials Read file content and write data to a file
Here is the main line of writing data to a file, but also a line to read the contents of the file.
*/
$fp = fopen ($_server[' document_root '). " /.. /data/info.dat ", ' R ');
if (! $fp)
{
echo "Error: Open file error, please check the directory is correct, or try again later!" ";
Exit
}
while (!feof ($FP))
{
$line = fgets ($FP);
Echo $line;
Echo '
';
}
Fclose ($FP);
Write a file
$file = "Data.txt";
$content = "Content title RNWWW.BKJIA.COMRN content second line"; What to write
if (! $fp = fopen ($file, ' a '))//When opening file $file, use append mode, at which point the file pointer is at the beginning of the file
{
echo "Open file $file failed!" ";
Exit
}
if (fwrite ($fp, $content) = = = False)//write content to file
{
echo "Failed to write to file! ";
Exit
}
echo "wrote the file successfully! ";
Fclose ($FP);
http://www.bkjia.com/PHPjc/445438.html www.bkjia.com true http://www.bkjia.com/PHPjc/445438.html techarticle PHP Read the contents of the file and write data to the file here is the main line of writing data to a file, also a line to read the contents of the file. PHP Tutorials Read file contents and write data to files ...