user4281203
user4281203

Reputation:

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.

Upvotes: 0

Views: 82

Answers (2)

user4281203
user4281203

Reputation:

I found a solution:

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

Upvotes: 1

Peter
Peter

Reputation: 16943

use 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.

Returns FALSE if the needle was not found. Warning

This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.

Upvotes: 3

Related Questions