简体   繁体   English

检查两个不同的字符串是否在php中包含两个不同的特定单词

[英]check if a two different string contain two different specific words in php

my code is: 我的代码是:

$key  = strtolower( trim( $_REQUEST['key'] ) );
$cat  = strtolower( trim( $_REQUEST['categories'] ) );
$loc  = strtolower( trim( $_REQUEST['locations'] ) );
$ttle = strtolower( trim( $title ) );
$lloc = strtolower( trim( $exp[0] ) );

/*I am not getting any results with this*/
if( (strstr( $ttle, $key ) && ( strstr($lloc,$loc) ) ) {
    //echo some thing
}

how can I find some if a two different string contain two different specific words. 如果两个不同的字符串包含两个不同的特定单词,该如何查找呢?

use strpos() : 使用strpos()

if((strpos($ttle, $key) !== false) && (strpos($lloc,$loc) !== false)) {
    //echo some thing
}

Returns part of haystack string starting from and including the first occurrence of needle to the end of haystack. 返回干草堆字符串的一部分,从第一个出现的针开始并包括到干草堆的结尾。

Returns the position of where the needle exists relative to the beginning of the haystack string (independent of offset). 返回相对于干草堆字符串起点的针所在位置(与偏移量无关)。 Also note that string positions start at 0, and not 1. 另请注意,字符串位置从0开始,而不是1。

Returns FALSE if the needle was not found. 如果找不到针,则返回FALSE。 Warning 警告

This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE. 此函数可以返回布尔FALSE,但也可以返回非布尔值,其值为FALSE。 Please read the section on Booleans for more information. 请阅读布尔值部分以获取更多信息。 Use the === operator for testing the return value of this function. 使用===运算符测试此函数的返回值。

I found a solution: 我找到了解决方案:

if( ( strstr($ttle, $key) != "" ) && ( strstr($lloc,$loc) !="" ) )  {
  //echo some thing  
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM