Weird php syntax! It is found that a php statement used to determine whether a string is a steamed stuffed bun string is quite strange.
See 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 "."
";
}
Else
{
Echo "abc not in "."
";
}
If (strpos ("u", "abc")> = 0)
{
Echo "abc in u "."
";
}
Else
{
Echo "abc not in u "."
";
}
Strpos
// Displayed result
A1: 0
A2: 1
B1:
B2: 1
A in abc
U in abc
Abc in
Abc in u
Definition and usage
The strpos () function returns the position where the string first appears in another string.
If this string is not found, false is returned.
Syntax
Strpos (string, find, start)
Parameter description
String |
Required. Specifies the string to be searched. |
Find |
Required. Specifies the characters to be searched. |
Start |
Optional. Specifies the location where the search starts. |
For example, if I want to determine whether the string "abc" contains "a", which method is better?