In SQL we have NOT LIKE %string%
I need to do this in PHP.
if ($string NOT LIKE %word%) { do something }
I think that can be done with strpos()
But can’t figure out how…
I need exactly that comparission sentence in valid PHP.
if ($string NOT LIKE %word%) { do something }
This question is related to
php
string-comparison
If you wanna find just the word like 'are' in "How are you?" and not like 'are' in 'hare'
$word=" are ";
$str="How are you?";
if(strpos($word,$str) !== false){
echo 1;
}
Use strpos
. If the string is not found it returns false
, otherwise something that is not false
. Be sure to use a type-safe comparison (===
) as 0
may be returned and it is a falsy value:
if (strpos($string, $substring) === false) {
// substring is not found in string
}
if (strpos($string, $substring2) !== false) {
// substring2 is found in string
}
<?php
// Use this function and Pass Mixed string and what you want to search in mixed string.
// For Example :
$mixedStr = "hello world. This is john duvey";
$searchStr= "john";
if(strpos($mixedStr,$searchStr)) {
echo "Your string here";
}else {
echo "String not here";
}
use _x000D_
_x000D_
if(stripos($str,'job')){_x000D_
// do your work_x000D_
}
_x000D_
Source: Stackoverflow.com