Use a text file to create a message board prompt (below)

Source: Internet
Author: User

Managing Your messages in text files is not as convenient as in the database. Next we will try to achieve this effect!
When outputting data, we use arrays to store data. Therefore, we can easily assign an sequence number to each group of data in order and operate on the sequence number, we can easily modify the data!
$ Date [0] is the first line in the text file. When we output the data, the allocation sequence number is 0.
The output has the following effect:

<A href = "modify. php? Id = 0'> modify message </a>
Let's customize modify. php.
<? Php
If ($ id! = ""){
$ Date = file ("txt/mytxt.txt ");
$ Str = explode ("&", $ date [0])
?>
<Form method = "post" action = "modify. php" onsubmit = "return check ()">
<Input type = "text" name = "tech1" value = <? Php echo $ str [0];? >>
<Input type = "text" name = "tech2" value = <? Php echo $ str [1];? >>
<Input type = "text" name = "tech3" value = <? Php echo $ str [2];? >>
<Input type = "submit" name = "Submit" value = "Submit">

</Form>
<? Php
} Else {
$ Str = $ tech1. "&". $ tech2. "&". $ tech3 ....
If ($ str! = ""){
// Write the modified data back to a text file!
}
}?>

In this process, note that the value of $ id is not lost. When writing back data, read the value in the text into $ date, and then $ date [$ id] = $ str;
$ Fp = fopen ("txt/mytxt.txt", "w ");
Fwrite ($ fp, $ date );
Fclose ($ fp );

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.