Find a sentence that PHP uses to determine whether a string is a bunch of buns rather weird.
Look at the following statement:
echo "A1:". (Strpos ("CSD", "C")). "
";
echo "A2:". (Strpos ("CSD", "C") >=0). "
";
echo "B1:". (Strpos ("CSD", "H", 0)). "
";
echo "B2:". (Strpos ("CSD", "H", 0) >=0). "
";
if (Strpos ("abc", "a") >=0)
{
echo "A in ABC". "
";
}
Else
{
echo "A not in ABC". "
";
}
if (Strpos ("abc", "U") >=0)
{
echo "u in abc". "
";
}
Else
{
echo "U not in abc". "
";
}
if (Strpos ("A", "abc") >=0)
{
echo "ABC in a". "
";
}
Else
{
echo "ABC not in a". "
";
}
if (Strpos ("U", "abc") >=0)
{
echo "ABC in U". "
";
}
Else
{
echo "ABC not in U". "
";
}
Strpos
The results displayed
a1:0
A2:1
B1:
B2:1
A in ABC
U in ABC
ABC in a
ABC in U
Definition and usage
The Strpos () function returns the position of the first occurrence of a string in another string.
If the string is not found, false is returned.
Grammar
Strpos (String,find,start)
Parameter description
String |
Necessary. Specifies the string to be searched. |
Find |
Necessary. Specifies the character to find. |
Start |
Optional. Specify where to start the search. |
Ask, here, for example I want to judge the string "abc" contains "a", which method is better?