"PHP" string-access substring

Source: Internet
Author: User

Problem

Want to know if a string contains a specific substring. For example, want to see if an email address contains an @.

Solve

if (Strpos ($_post[' email '), ' @ ') = = = False) {    echo ' there is no @ in the e-mail address! ';}

Discuss

  1. The return value of Strpos () is the first occurrence of a substring in a string

  2. If there is no substring at all in the string, Strpos () returns false

  3. If the substring is at the starting position of the string, Strpos () returns 0 because position 0 represents the starting position of the string.

  4. To distinguish between 0 and false, you must use the identity operator (= = =) or the non-identity operator (!==)

  5. The above example uses the = = = To compare the return value of Strpos () with false. This test succeeds only if Strpos () returns false, and if Strpos () returns 0 or any other number, the test will not succeed


Related Article

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.