ComputersFile Types

How to write to the php file

If you master the work with php yourself, 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

If a file has such an extension, it means it contains the 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 site, you often need to use 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

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.
The fact that you can write data to a php file, you can notify another function is_file (). 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

The first tool you can use to make changes to the 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 by choice. For students, fwrite is more common, and practicing programmers often use fputs.

To make a php entry in a text file, you must 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.

// 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 general-purpose scripting language. 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.

Similar articles

 

 

 

 

Trending Now

 

 

 

 

Newest

Copyright © 2018 en.atomiyme.com. Theme powered by WordPress.