PHP Forum technology core-hierarchical storage and display and back-to-back
Source: Internet
Author: User
1. Save the speech and reply by file name // Responses 2 display method 1 save the speech and reply by file name
// Max.txt stores the maximum total number of speech titles (excluding replies)
Forum classification file...
The name of the first speech is 1.txt.
The first reply to the speech is "statement 1.txt ".
The reply to the first speech 2 is called commit 2.txt.
Reply 2 of the first statement. 1 is 1_2_1.txt.
The name of the second speech is 2.txt.
2 Display method
// Get the total number of headers (excluding replies)
$ Max = file ("max.txt ");
// Display by page
If ($ page = "")
{
$ Page = 1;
}
// The number of titles displayed on each page
$ Numperpage = 20;
// Total number of titles
$ Total = $ max [0];
// Total number of pages
$ Totalpage = round ($ total + $ numperpage/2)/$ numperpage );
// Hierarchical display function
Function show ($ filename)
{
// $ Id indicates the category name of the Forum.
Global $ id;
// Read the speech to be displayed
$ Filenamemsg = file ($ filename );
/Search for any replies
For ($ I = 1; I I <999999; $ I ++)
{
// Find the reply file with the file name _ number
$ Tmp = $ filename. "_". $ I;
If (file_exists ($ tmp ))
{
// If yes, call recursive display of the reply and Reply
Print ("
\ R \ n ");
Show ($ tmp );
Print ("
\ R \ n ");
}
Else
{
// Otherwise, the interrupted loop
Break;
}
}
// Classification display ends
Print ("");
}
// Start with pagination
$ Begin = $ total-($ page-1) * $ numperpage;
// The page display ends.
$ End = $ begin-$ numperpage;
// Start of hierarchical display
Print ("
");
// Display the title and replies at all levels in a loop
For ($ I = $ begin; ($ I> 0) & ($ I> $ end); $ I --)
{
Show ("$ I ");
}
// Classification display ends
Print ("
");
3. how to post new articles
// Process the maximum number of speakers
$ Max = file ("max.txt ");
$ Maxnumber = $ max [0] + 1;
$ Handle = fopen ("max.txt", "w ");
Fputs ($ handle, $ maxnumber );
Fclose ($ handle );
// Create a Speech title file
$ Handle = fopen ("$ maxnumber", "w ");
// Pre-process the speech
$ Name = ereg_replace ("<", "<", $ name );
$ Name = ereg_replace (">", ">", $ name );
If (strlen ($ name)> 20)
{
$ Name = substr ($ name, 0, 20 );
}
$ Subject = ereg_replace ("<", "<", $ subject );
$ Subject = ereg_replace (">", ">", $ subject );
If (strlen ($ subject)> 100)
{
$ Subject = substr ($ subject, 0,100 );
}
$ Body = ereg_replace ("<", "<", $ body );
$ Body = ereg_replace (">", ">", $ body );
$ Body = ereg_replace ("\ r \ n ","
", $ Body );
If (strlen ($ body)> 5000)
{
$ Body = substr ($ body, 0,5000 );
}
// Save your speech
Fputs ($ handle, "$ name | bbs | $ email | bbs | $ subject | bbs | $ body | bbs | ".
Date ("Y, m, d, H: I "));
Fclose ($ handle );
4. hierarchical storage of replies
// The method is basically the same as the statement, but some judgment is added.
// Note that $ filename indicates the name of the speech file.
// However, the title file name is 1.txt
// It may also be the response file named 13_3_2.txt, which contains 13th replies for the first reply in the title of the first speech.
// Find the maximum number of replies
For ($ I = 1; I I <999999; $ I ++)
{
If (! File_exists ($ filename. "_". $ I ))
{
Break;
}
}
// Locate and create a new reply file
// The Post is the same as the speech
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