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.
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.Example 2:
$text = "webattribute.blogspot.com";
if( strpos($text,"webattribute") !== false ){
// TODO - When specific word found
} else {
// TODO - When specific wordd not found
}
Hopefully the little knowledge I've shared this useful for you. Thank you.

0 komentar:
Posting Komentar