Generate the php code of the php program. A. php file that contains the program start character (). the specific code is placed between the start character and the end character. In order to facilitate future modification and program reading, the code should follow certain rules to create a. php file that contains the program start character (). the specific code is placed between the start character and the end character. In order to facilitate future modification and program reading, traditionally, code should be divided according to certain regulations, while php code must have a variable identifier ($ ). All of these problems cause some trouble to generate. php files, and some workarounds are required to process them.
Let's first process the start and end characters of the php program file. this is not complicated. We use two variables to represent them:
$ Str_tmp =" $ Str_end = "?> "; // Terminator. $ Str_end is an independent variable.
Let's process the variable identifier ($). let's see a variable equation in the generated. php file: $ age = "28 ";. The code is as follows:
$ Str = "$". "age = \" 28 \ "; \ r \ n ";
In the above formula, print the variable $ str to get the expected effect. In the code, $ and age must be separated and used with the connection number (.) combine it to get the effect of $ age. the symbol (\ ") indicates a small double quotation mark ("); the end of a php code line must contain a semicolon (;); \ r \ n indicates to press enter to start another line.
The above solves the php code start character, end character, code variable sign, equation and other input problems, now you can go to the specific operation to generate the. php file. To make the program look like this, we preset the content of the. php file to be generated: user name (Dark Horse), logon password (blackhorse), age (28), Revenue (4500 ). The complete code for generating the. php file is as follows:
// Collect information
$ Str_tmp =" $ Str_end = "?> "; // Php Terminator
$ Str_tmp. = "$". "name = \" \ "; \ r \ n"; // add user name
$ Str_tmp. = "$". "pass = \" blackhorse \ "; \ r \ n"; // add the password
$ Str_tmp. = "$". "age = \" 28 \ "; \ r \ n"; // add to age
$ Str_tmp. = "$". "income = \" 4500 \ "; \ r \ n ";
$ Str_tmp. = $ str_end; // add the Terminator.
// Save the file
$ Sf = "blhorse. php"; // file name
$ Fp = fopen ($ sf, "w"); // open a file in write mode
Fwrite ($ fp, $ str_tmp); // store the content
Fclose ($ fp); // close the file
?>
Save the above code as a file named test. php and run it to get the blhorse. php file. the complete content of this file is as follows:
$ Name = "";
$ Pass = "blackhorse ";
$ Age = "28 ";
$ Income = "4500 ";
?>
We can see that what we get is a fairly standard. php configuration file that fully meets our requirements. As for writing more complex. php files, it is quite easy to implement as long as the assignment and accumulation of variables are handled as shown in the code in this article.
Break (). the specific code is placed between the start character and the end character. In order to facilitate future modification and program reading, the customary code should follow certain rules...