May I tell you how to judge different keywords?

Source: Internet
Author: User
Ask for the judgment of different keywords. This post was last edited by okgef from 2015-10-2810: 43: 24. if I set some keywords $ words, Hello | query | weather | name | data; how can we determine whether the submitted $ _ POST [post] content contains the keywords to make different judgments? Currently, we can only use strpos () & gt; 0. ask for the judgment of different keywords.

This post was last edited by okgef at 10:43:24

If I set some keywords $ words = "Hello | query | weather | name | data ";
How can we determine whether the submitted $ _ POST ['post'] content contains the keywords to make different judgments?
Currently, only if such as strpos ()> 0 can be used, and then if ,...... Else {}
Is there any other way?
If the submitted content contains "Hello", run code A. If it contains "weather", run code B. If multiple keywords are included at the same time, take the first one that appears.
------ Solution ----------------------

$ Post = 'name query ';
If (preg_match ('/(hello
------ Solution ----------------------
Query
------ Solution ----------------------
Weather
------ Solution ----------------------
Name
------ Solution ----------------------
Data)/I ', $ post, $ m )){
$ Keyw = $ m [1];
// It is better to use the switch
If ($ keyw = ''){
Echo 'hello code ...';
} Elseif ($ keyw = 'query '){
Echo 'query code ...';
} Elseif ($ keyw = 'weather '){
Echo 'weather code ...';
} Elseif ($ keyw = 'name '){
Echo 'name code ...';
} Elseif ($ keyw = 'data '){
Echo 'data code ...';
}
}

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.