[PHP] string-access substring

Source: Internet
Author: User
Want to know whether a string contains a specific substring. For example, you want to check whether an email address contains @. Problem

Want to know whether a string contains a specific substring. For example, you want to check whether an email address contains @.

Solution
If (strpos ($ _ POST ['email '],' @ ') === false) {echo 'there was no @ in the e-mail address! ';}
Discussion
  1. The return value of strpos () is the first position of the substring in the string.

  2. If no substring exists in the string, strpos () returns false.

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

  4. To distinguish between 0 and false, the constant operator (=) or non-constant operator (! =)

  5. In the preceding example, use = to compare the return value of strpos () with false. This test succeeds only when strpos () returns false. if strpos () returns 0 or any other number, the test fails.


For more [PHP] Strings-for articles about accessing substrings, refer to the PHP Chinese website!

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.