PHP public development notes (8)
PHP public development notes Series
Date: 2014.9.6
Today, we need to build a keyword database, a timeout mechanism, optimized keyword matching, and an emoticon database.
Note: No results are returned after PHP echo? Will the execution continue ??
Sort notes:
When I write this note, I am catching up with the function. So I simply remember a few pieces of work at that time. Now the function is almost developed, so I will sort out the previous notes. At that time, it was easy to record the above statements.
This day is Saturday, so I don't have to work overtime and rest in the rented house. Because of the Mid-Autumn Festival, my sister in Shenzhen will come to my side for a holiday, so there is not much time to write functions on this day. When I get up early in the morning and come back, I start to get involved. (now think about it, maybe I will become a workaholic in the future ). The function of this day is to create a keyword data table, emoticon data table, add a timeout mechanism, and optimize keyword matching in the database.
I. Keyword data table
The information stored in this data table is mainly the keywords used for keyword filtering and capturing. To facilitate management, let's think about putting the information in the database, write a function to retrieve the information, and then perform matching, in this way, I do not need to write all the information into the code, which is more flexible. With this idea, we began to sort out the data table.
There is nothing special to mention about database operations. Here we mainly record the operations in the Code:
1. First, obtain all the keywords:
This is very simple, that is, to get the entire data of the keyword data table in the database:
Select * from xxx select the information of the data table xxx;
Store the obtained information to a two-dimensional array:
VcHLy/nT0LXEudi8/LTK0MXPosHLoaM8YnI + hour/bPwtK7sr21xLmk1/hour + 3b/io6y2 + hour/hour + hour = "http://www.2cto.com/uploadfile/Collfiles/20140912/2014091209032020.png" alt = "\">
As shown in the code, I get the data row of this keyword in the data table, and then perform the next step based on its type (the data table contains the fields keyword and keyword type, with these two information, I can perform corresponding operations based on the keyword type ):
The subsequent operation is to directly use the previous Code. Here I just took a look at the structure. Optimized keywords mentioned
2. emoticdb
The reply message can be used to reply to the expression. Here I am not using the emoji expression, but the most common one. For example, "Smile" is represented, the table I created uses a smile as the keyword and a "/: :)" as the value, and then adds an emoticon type. The three fields are in total. When using it, you can simply enter a smile and get its value and then reply to it. It is only related to database operations, so there will be no worries here.
Iii. Timeout Mechanism
Because the Public Account uses $ _ SESSION to store information such as user authentication, and the selected menu type. It is necessary to clean up these items on a regular basis. For example, if the user selects the menu and does not use it for a long time, it is best that the menu is not used for the next time, but should be exited. For this reason, I checked the relevant information online: either clear all the $ _ sessions on a regular basis or clear a single $ _ SESSION on a regular basis. To be regular, you need to know the time. In combination with the things I used in the previous mobile game project, you just need to remember the start time when you want to do it regularly, then you can make a judgment every time you use it.
In terms of implementation, I first record the time when a $ _ SESSION is stored, for example, the time when the user identity is verified:
Psa_time () is only a package of the time () function provided by the system. In this way, I get the authentication time, and then I get the current time for each user operation to compare with the recorded time:
In this way, the so-called timeout mechanism is implemented.
PHP learning records:
After echo, will the function still be executed? Previously, my reply information was not controlled in a unified manner. Maybe I will reply directly to some modules. However, I found that even if I use echo to reply to a message, the code segment after echo will still be executed. I don't know what the situation is.