In the PHP programming algorithm, sometimes we will need to check if in a string containing a particular word. It is not hard to do. In the innate function of PHP, there are functions that can to do this with ease, it is strpos function.
Basically
strpos function is used to determine the position of a character or a word or a sentence fragment.
Example 1:
$text = "abcdef";
$pos_a = strpos($text,"a"); // $pos_a = 0
$pos_c = strpos($text,"c"); // $pos_c = 2
$pos_f = strpos($text,"f"); // $pos_c = 5
This function will return the position of specific character or word that we need or return false if not found.
Example 2:
$text = "webattribute.blogspot.com";
if( strpos($text,"webattribute") !== false ){
// TODO - When specific word found
} else {
// TODO - When specific wordd not found
}
In the above example, ofcourse the string contains the "webattribute" word in the zero position. And remember that zero is not the same as false (0! == False). Therefore, in the above case, the command will be executed is defined command if the string contains the "webattribute" word.
Hopefully the little knowledge I've shared this useful for you. Thank you.