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 ...';
}
}