Php operations on php files

Source: Internet
Author: User

Does it sound dizzy ?!! Use php to operate php pages. There is a small purpose. In a system, there may be some small items that cannot be stored in the database, but we need to call them frequently on other pages and update them, then we can solve it in this way. I encountered a few small problems and it took me half a day to solve them.

For example, you need to change a title, but creating a table for this title is obviously not suitable. So I thought about writing this variable into the PHP file for other pages to call. The name. php file requires the following content:

<?

$ Name = "title ";

?>

You can update the word "title. How can we achieve this:

Add_name.php

<Form action = "addname. php" method = "post">
<Input type = "text" name = "name" size = "20"/>
<Input type = "submit" value = "submit"/>

Addname. php

<?
$ Name = $ _ POST [name]; // receives the name value from add_name.php.
If (empty ($ name) {// determines whether it is null
?>
<Script language = javascript>
Alert ("name cannot be blank! ");
Document. location = add_name.php;
</Script>
<?
} Else {
$ Filename = "name. php"; // defines the operation File
$ Delline = 2; // number of rows to be deleted
If (! File_exists ($ filename) {// checks whether a file exists.
Die ("the specified file is not found! Operation interrupted! ");
}
$ Farray = file ($ filename); // read file data to the array
For ($ tmpa = 0; $ tmpa <count ($ farray); $ tmpa ++ ){
If ($ tmpa + 1) = 2) {// determine the number of rows
$ Farray [$ tmpa] = "$ name2 =". "". $ name ."";";*
// Replace the data of the original row
} // Reorganize the data
$ Newfp. = $ farray [$ tmpa];
}
$ Fp = @ fopen ($ filename, "w") or die ("failed to open file $ filename in write mode ");

// Open the file in writing mode

@ Fwrite ($ fp, $ newfp) or die ("file write failed ");

@ Fclose ($ fp); close the file
}
?>

This code is only used for testing with 117-202 1Z0-043 1z0-042. Where the writing is not standardized, it's just a little bit of a smile!

In this way, we can update the variables in the name. php file. Of course, this is a stupid method (who makes me stupid ). There are many ways to implement this requirement.

Here, we use escape characters in the line marked by *. This is simple to say, but it is a waste of time because of the method. Now, paste the escape tables below:

Escape Character Sequence meaning
Line feed (LF or ASCII character 0x0A (10 ))
Press enter (CR or ASCII character 0x0D (13 ))
Horizontal tab (HT or ASCII character 0x09 (9 ))
\ Backslash
$ Dollar sign
"Double quotation marks

[0-7] {} The regular expression sequence matches a character represented by the octal symbol
X [0-9A-Fa-f] {} This regular expression matches a character in a sequence expressed in hexadecimal notation


To process a single string, using single quotes is faster than using double quotes, so you need to select the appropriate quotation marks in your program.

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.