A detailed explanation of how PHP handles string-like IndexOf method functions

Source: Internet
Author: User
This article mainly introduces the details of PHP processing string similar to IndexOf method function of the relevant data, the need for friends can refer to the following

A detailed explanation of how PHP handles string-like IndexOf method functions

There are two functions or methods that handle strings like indexof in PHP, which are strpos functions and STRIPOS functions, which are similar in usage.

When the Strpos function processes a string, it returns the first occurrence of the string if it contains the string, or False if it does not appear. Sensitive to string case.

When the Stripos function processes a string, it returns the first occurrence of the string if it contains the string, or False if it does not appear. Not sensitive to string case.

PHP Strpos () function

Definition and usage

The Strpos () function finds the position of the first occurrence of a string in another string.

Note: the Strpos () function is case-sensitive.

Note: This function is binary safe.

Grammar

Strpos (String, find, start)

Parameter description

String: Required. Specifies the string to search for.
Find: Required. Specifies the string to find.
Start: Optional. Specify where to start the search.

return value

Returns the position of the first occurrence of a string in another string, or FALSE if no string is found.

Note: The string position starts at 0, not from 1.

Example

<?phpecho strpos (' Hello world! ', ' wo ');? >

Output: 6

PHP Stripos () function

Definition and usage

The Stripos () function finds the position of the first occurrence of a string in another string.

Note: the Stripos () function is case insensitive.

Note: This function is binary safe.

Grammar

Stripos (String,find,start)

Parameter description

String: Required. Specifies the string to search for.
Find: Required. Specifies the string to find.
Start: Optional. Specify where to start the search.

return value

Returns the position of the first occurrence of a string in another string, or FALSE if no string is found.

Note: The string position starts at 0, not from 1.

Example

<?phpecho stripos (' Hello world! ', ' WO ');? >

Output: 6

Thank you for reading, hope to help everyone, thank you for the support of topic.alibabacloud.com!

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.