answersLogoWhite

0

Write a PHP program to read and write a text file?

Updated: 8/17/2019
User Avatar

Wiki User

14y ago

Best Answer

Oh this is easy =P

Lets say or file is "file.txt"

$fopen = fopen('file.txt','r+'); // Open the file with read and write permissions. However, this will write overwrite the contents of the file when written. To fix it, change r+ to a+.
$write = "Message to be written";
fwrite($fopen,$message); // Writes the message ($message) to the file. $fopen picks the file.
fclose($fopen); // Closes the file.
?>

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a PHP program to read and write a text file?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are typical access rights that may be granted or denied to a particular user for a particular file?

Read, write, execute, and functions in software objects.


What file systems does Ubuntu support?

Ubuntu supports a large number of file systems, including ext2 (read/write), ext3 (read/write), ext4 (read/write), ReiserFS (read/write), JFS (read/write), XFS (read/write), FAT (read/write), and NTFS (read, additional software available for writing). With the exception of NTFS, it can also boot off of the above file systems.


What is meant by read and write txt in file handling?

read: moving data from file to memory write: moving data from memory to file


Write java program to merge alternate lines from file1 and file2 into file1?

I suggest something like this:* Open file1 and file2 * Create a temporary output file, for writing * Read a line from file1, write it into the output file * Read a line from file2, write it into the output file * Repeat the previous two steps, while you are not at end-of-file in either of the two files * At this point, if you are NOT at end-of-file in file1, read the remaining lines of file1, and write them to the output (you can write a loop for this). * Similarly, if you are NOT at end-of-file in file2, read and write the remaining file. * Close file1, file2, and the output file. * Copy the temporary output file back to file1 * Erase the temporary output file


How do you read and write video file in java?

you can use inputstream for reading the file java.io.fileinputstream and write the file using outputstream..


What abilities does the NTFS write permission grant?

Write to the file, append to the file, and read or change its attributes.


How can you read and write to files in C programming language?

We can read and write to files with the help of file commands in c programming.There are so many commands related to file for read,write,append,delete etc.


What are the permissions of a new text file?

Read,Write and Execution permissions. r- Read w- Write x- Execution


What is the difference between read and write in computer programming?

A "Read" operation occurs when a computer program reads information from a computer file/table (e.g. to be displayed on a screen). The "read" operation gets information out of a file (some computer languages use the term "get" instead of "read"). After a "read", the information from the file/table is available to the computer program but none of the information that was read from the file/table is changed in any way. A "Write" operation occurs when a computer program adds new information, or changes existing information in a computer file/table. An example of a computer program adding new information to a file would be when a company adds a new hire's details into its employee master file. An example of a computer program changing existing information would be when a company updates its employee master file if an existing employee changes their address. In this example, since the employee already existed in the employee file, the computer program would have had to perform a "read" at some point, to get the information out of the file/table (a fundamental rule of computer programming is that you can't update a record in a file/table unless you perform a "read" operation to get a hold of that record in the first place). Either way, the "Write" operation is what puts information in to a file. Some computer languages use the terms "put" or "update", but these are both "write" operations in general IT terms. Bottom line: Read = get information. Write = add or change information. HTH


How to write a C program to find the header record in a file .please advice?

Just open the file, read-in N bytes and then examine (parse) for known header values or signature.


How you can delete the data in the file when you open the file in read or write mode in C programming?

When you open a file in write mode, eg. fp=fopen("filename.txt","w"); the content of the file is deleted.


How do you get your English perfect?

Read read read read. And then write write write write.