PHP-strpos function

The strpos function in PHP is used to determine whether a string is contained in another string.

For Example

If there is a string A that contains the following words “The cat is sleeping” and you have another string B that contains this “cat”

One could use the strpos function to determine whether string B belongs to any element is string A. In this case the word cat from string B is present in string A

 

The If Statement

 if( (strpos($A,$B)!==false){

echo “True”;

}

else{

echo “False”;

}

Will return True since string B belongs to string A

The common use of this function is to determine the position of the first occurrence of the substring in a string

strpos(string,substring)

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s