Today, I was occupied again during the day, sorted out my recent schedule at night, and made another trip to my Cainiao PHP study. Today, I downloaded a Chuangjia PHPTXT message board version 1.0 and started to read the source code. It is now am ~. First, I was occupied again in the daytime under index. php, sorted out my recent schedule at night, and again posted my rookie PHP study tour. Today, I downloaded a "Chuangjia PHPTXT message book version 1.0" and started to read the source code. It is now am ~.
First, start with index. php: require ("config. php"); include ("function. php"); the difference between require and include is more important. Manual: http://cn2.php.net/manual/zh/function.require.php.
Now let's take a look at what is in config. php and function. php.
Config. php defines the variables used by the entire website, such as the administrator account, password, message storage path and file name, and the number of message entries displayed on each page. Remember that there is also such a thing in Discuz. maybe this is an unwritten rule for all PHP sites?
Function. php defines a series of functions, such as checking the user name and password and converting the UBB code, but I do not know what the UBB code is ~. No longer.
Return to index. php. The following defines several variables that do not know what to use for the moment. it is depressing to go over for the moment. Then there is a header function http://cn2.php.net/manual/zh/function.header.php. Contains a file named head. php. Use file () to read the file that saves the message to an array named msgd. Http://cn2.php.net/manual/zh/function.file.php
Today, I probably understood the source code, but it's too late to write it for the moment. let's talk about it later. You should install a Word and copy it directly (I don't know why I don't have Word ~~ on my machine ~~). In short, I have a rest today. I have no time in the daytime tomorrow. I don't want to go home to stay at night. I will send people to the train station the next day and then go back to school. I really don't know when I can continue my PHP.
Require ("head. php"); contains a file, but the head seems to be contained only by index. php. I don't know why I didn't write it directly. The head Code mainly provides a form for searching messages.
$ Msgd = file ($ dbtable); $ dbtable is defined in config, $ dbtable = "data/data. dat"; this file is used to save messages. The file function is used to save the file in the $ msgd array. Each row of the file is an array element.
$ Rows = count ($ msgd); here, the count function is used to store the number of elements (messages) of $ msgd in $ rows.
If ($ kw) // keyword to determine whether to search
{
For ($ I = 0; $ I <= $ rows; $ I ++) // Traverse
{
$ Tmp2 = explode ("| delimiter |", $ msgd [$ I]); // no message exists in the tmp2 array.
If ($ type = "name") // search by name
{
$ Msgn [$ I] = $ tmp2 [1]; // you can specify a name in $ msgn [$ I ].
} Else // If you do not search by name
{
$ Msgn [$ I] = $ tmp2 [10]; // store the 10th elements in the message array in msgn [$ I]
}
If (eregi ($ kw, $ msgn [$ I])
{
$ Chj_nr [] = $ msgd [$ I]; // use an array $ chj_nr [] to store a complete message
$ Chj_numib ++; // number of messages meeting the requirements
}
}
If ($ chj_numib <1) {echo "no matching result for $ kw !! "; Exit ;}
$ Msg = array_reverse ($ chj_nr); // returns an array of messages that match the search results.
$ Total = ceil ($ chj_numib/$ pagesize); // calculates the total number of pages.
} Else // if it is not a search
{
$ Chj_numib = $ rows; // All messages
$ Msg = array_reverse ($ msgd );
$ Total = ceil ($ chj_numib/$ pagesize );
}
// Echo $ total;
If ($ pagesize * $ total <$ chj_numib)
{
$ Total ++;
}
$ Total2 = $ total-1; // The following is useful:
$ Page2 = $ page + 1; // same as above
$ Pp = $ page * $ pagesize; // calculate the number of start entries // start of the current page
$ Pp2 = $ pp + $ pagesize; // calculate the number of end entries // same as above
$ Nextpage = $ page + 2; // The Next page
$ Prevpage = $ page; // Previous page
For ($ I = $ pp; $ I <$ pp2; $ I ++) // this for loop is used to output all messages that match your needs (array $ msg)
{
If ($ I <$ chj_numib ){#####
$ Tmp = explode ("| chjia_com |", $ msg [$ I]);
$ Tmp [10] = epost ($ tmp [10]);
?>
A message is output later. Here, index. php is basically finished.
The above is the content of Cainiao's PHP Note 3. For more information, see The PHP Chinese website (www.php1.cn )!