Weird PHP syntax, solving!

Source: Internet
Author: User
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?

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.