A. php file that contains the program start character (), and the specific code is placed between the start and Terminator. In order to facilitate future changes and program reading, the custom code should be in accordance with certain provisions of the branch, and PHP code must not be a variable tag ($). All of this creates a certain amount of trouble with generating. php files, which require some workaround.
Let's deal with the start and Terminator of the PHP program file, which is not too complicated, and we use two variables to represent them:
$str _tmp= "<?php"; The start character. $str _tmp is a variable that is about to accumulate.
$str _end= "?>"; Terminator $str _end as an independent variable.
Here's how to handle the variable marker ($), and we'll have one of these variable equations in the generated. php File: $age = "28"; The code is as follows:
$STR = "$". " Age=\ "28\"; \ r \ n ";
In the upper, the print variable $str will have the desired effect. In the code, the $ and age are separated and combined with the connection number (.) To get the $age effect, the symbol (\) is the Pee double quotation mark ("), the PHP code line ends with a semicolon (;), and \ r \ n means to enter a return line.
We have solved the PHP code start, terminator and code variable flags and equations, and other input problems, can now be specific to the production of the. php file operation. To make the program look like, we preset the contents of the. php file that is about to be generated: username (Dark Horse), login password (blackhorse), age (28), Revenue (4500). Here is the complete code to generate the. php File:
<?php//-test.php--//
Collect information
$str _tmp= "<?php\r\n"; Get the PHP start character. $str _tmp will accumulate
$str _end= "?>"; PHP End Character
$str _tmp.= "$". " Name=\ "Black horse \"; \ r \ n "; Add user Name
$str _tmp.= "$". " Pass=\ "blackhorse\"; \ r \ n "; Add password
$str _tmp.= "$". " Age=\ "28\"; \ r \ n "; Join age
$str _tmp.= "$". " Income=\ "4500\"; \ r \ n ";
$str _tmp.= $str _end; Add End character
Save File
$SF = "blhorse.php"; Filename
$FP =fopen ($SF, "w"); Write way to open a file
Fwrite ($fp, $str _tmp); Deposit Content
Fclose ($FP); Close File
?>
Save the above code as a file named test.php, run it, get the blhorse.php file, the full contents of the file are as follows:
We can see that we are getting a fairly standard. PHP configuration class file, fully meet our requirements. As far as writing more complex. php files, as shown in this article code to handle the variables of the assignment and the accumulation of variables, it becomes quite easy to achieve.
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