If you independently learn to work with php,it is important to learn how to read data from a file and enter changes into it. The php file is written to develop web applications, modify server information, and run external programs and inclusions.

How to work with php files

writing to the php file
If the file has such an extension, it meansin itself it contains program code written in the same programming language. In order to make changes, you will need to install one of the software editors on your PC:

• PHP Expert Editor;
• Dreamweaver;
• Eclipse PHP Development;
• PHPEdit.

If you are creating a website, you often need toUse identical designs that are conveniently stored as templates in another file. For this it is better to use include. After entering this function, you need to write to the php file of the name and extension of the connection, for example, include 1.php. This design supports the ability to read the attached file multiple times, and an additional feature is the continuity of code execution on error. If something goes wrong, the code will continue to be executed from a new line.
So you connect the file to your code. Another way is to enter require. Unlike the above include, the file is connected before the execution of the program code, but you can access it only once.

File validation

php write to text file
Before you write to the php file,you need to make sure that it exists, and then open it and make the necessary editing. To do this, you can use the function file_exists (), if it confirms the presence, then the answer will be returned in the editor window, TRUE, otherwise - FALSE.
That you can write data to a php file, youcan notify the other is_file () function. It is more reliable than file_exits, and most programmers use is_file to get started. After you are convinced of the existence of the file, you can start working with it.

Making changes to the file

writing data to a php file
The first tool you can use to make changes to a file is fwrite (). It writes the lines with the following syntax:

• Int - manipulator;
• String is a variable.

There is one more analogous to this function -fputs (), which is an alias. There are no differences between these tools, one or the other can be used. For students, fwrite is more common, and practicing programmers often use fputs.

To make a php entry into a text file, it is necessary to observe one important condition - it must be open for edits. Such a file should be located in a folder with write permissions.

To work, try to open a text document in the program first, and then make corrections using conventional tools.

<? php
// Open the text file
$ f = fopen ("text.txt", "w");
// Write a line of text
fwrite ($ f, "Hello! Good day!");
// Close the text file
fclose ($ f);

In this example, text.txt is the name of the document. You can name it differently: "Hello! Good day! "Is an example of a text, it can be completely arbitrary. All changes are automatically saved in an open file.

Note that PHP is a common scripting languagedestination. It is used extensively to create web applications. This solution is supported by the majority of hosting providers. This is the leader among the tools that are used to create websites. Now you know how to write to the php file.

</ p>