Introduction: this is the core technology of the PHP Forum-detailed page for hierarchical storage, display, and return. It introduces PHP, related knowledge, skills, experience, and some PHP source code.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 324401 'rolling = 'no'>
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
<?
// Obtain the titleArticleTotal (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 );
// Split
$ MSG = Split ("\ | BBS \ |", $ filenamemsg [0], 99 );
// Display the current title
Print ("<li type = square> <a href = # onclick = \" window. Open ('detail. php? F
Ilename = $ filename & id = $ id ', 'detail', 'menubar = 0, toolbar = 0, location = No, s
Tatus = No, directories = 0, scrollbars = Yes, resizable = No, Left = 10, Top = 10, widt
H = 550, Height = 400 ') \ ">". $ MSG [2]. "". $ MSG [0]. "".
$ MSG [4]. "\ r \ n ");
/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 (">", "& gt;", $ name );
If (strlen ($ name)> 20)
{
$ Name = substr ($ name, 0, 20 );
}
$ Email = ereg_replace ("<", "<", $ email );
$ Email = ereg_replace (">", "& gt;", $ email );
If (strlen ($ email)> 50)
{
$ Email = substr ($ email, 0, 50 );
}
$ Subject = ereg_replace ("<", "<", $ subject );
$ Subject = ereg_replace (">", "& gt;", $ subject );
If (strlen ($ subject)> 100)
{
$ Subject = substr ($ subject, 0,100 );
}
$ Body = ereg_replace ("<", "<", $ body );
$ Body = ereg_replace (">", "& gt;", $ body );
$ Body = ereg_replace ("\ r \ n", "<br>", $ 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
Fclose (fopen ($ filename. "_". $ I, "W "));
Unlink ("reply. tmp ");
$ Handle = fopen ($ filename. "_". $ I, "W ");
$ Name = ereg_replace ("<", "<", $ name );
$ Name = ereg_replace (">", "& gt;", $ name );
If (strlen ($ name)> 20)
{
$ Name = substr ($ name, 0, 20 );
}
$ Email = ereg_replace ("<", "<", $ email );
$ Email = ereg_replace (">", "& gt;", $ email );
If (strlen ($ email)> 50)
{
$ Email = substr ($ email, 0, 50 );
}
$ Subject = ereg_replace ("<", "<", $ subject );
$ Subject = ereg_replace (">", "& gt;", $ subject );
If (strlen ($ subject)> 50)
{
$ Subject = substr ($ subject, 0, 50 );
}
$ Body = ereg_replace ("<", "<", $ body );
$ Body = ereg_replace (">", "& gt;", $ body );
$ Body = ereg_replace ("\ r \ n", "<br>", $ body );
If (strlen ($ body)> 500)
{
$ Body = substr ($ body, 0,500 );
}
Fputs ($ handle, "$ name | BBS | $ email | BBS | $ subject | BBS | $ body | BBS | ".
Date ("Y, M, D, H: I "));
Fclose ($ handle );
If you do not understand, go to my bamboo to download my ForumSource codeLet's take a look !!!
More articles on "php Forum technology core-hierarchical storage, display, and return"
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/324401.html pageno: 15.