PHP read file contents and write data to file _php tutorial

Source: Internet
Author: User
Tags php read file
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 ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.