This article mainly introduces the fourth course of php public account development. php implements simple text communication, which has a certain reference value, interested friends can refer to this article to introduce the fourth course of php public account development. php implements simple text communication, which has some reference value. interested friends can refer to it.
We know that the public account development subscribe number and service number, while an individual can only apply for a subscribe number, the subscribe number cannot be set to a menu, but can only be achieved by keyword reply, for example, I reply to help, the help information is returned. if I reply to the movie, the detailed link of the movie is returned, which is a keyword reply in a specific format.
Create a new table, such as the t_type table, which is used to input keywords and return specific text. Here we select the development mode. in order not to change the code every time, we write the keywords and return values into the data table, set the table Field id, type, and value.
In the previous section, we obtained the text input value $ keyword. now we use this keyword to go to the database table t_type and query the input value to implement some keywords. the returned value is a simple and specific return function,
For example, if you enter help, return help information, enter translation, and I love you, then you can translate. if you enter mobile phone 18200000000 to return the home location, and if you can directly return the text, you can store the value, such as help information, if the translation needs to be processed, the database will store the fanyi value and the mobile phone 1820000000 will store shouji. how can this problem be solved? Read the code.
$ Str2 = mb_substr ($ keyword, 0, 2, 'utf-8 '); // The first two characters $ SQL = "select value from t_type where type = '$ keyword' or type =' $ str2 'limit 1"; $ res = mysql_query ($ SQL ); $ rs = mysql_fetch_array ($ res); if (! Empty ($ rs) {switch ($ rs [0]) {case "shouji": // query function break;} else {// The database is not found for processing}
In this way, you can enter the mobile phone + number to query the location of the region. The translation is similar. to add a function, you only need to set the keywords and values through the database.
In this way, all functions can be classified, such as common ID card locations, IP address queries, and movies.
The above is all the content of this article. I hope it will help you learn and support PHP.
For more information about php public code development and custom keywords, please follow the php Chinese website!