Php WeChat public account development (4) php implement custom keyword Reply

Source: Internet
Author: User
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. 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 the php public code development (4) php to implement custom keyword reply content. For more information, please follow the PHP Chinese network (www.php.cn )!

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.