PHP Strpos () function instance detailed

Source: Internet
Author: User
What is the function of PHP strpos ()?

The Strpos () function finds the position of the first occurrence of a string in another string. It is important to note that this function is case-sensitive and, contrary to the PHP Stripos () function, the Stripos () function is case insensitive. This article leads you to the PHP Strpos () function.

Syntax for PHP strpos () function

Strpos (String,find,start)

Detailed parameters:

The function has three parameters, where the first two parameters are necessary, the third parameter is optional

Parameters Description
String Necessary. Specifies the string to be searched.
Find Necessary. Specifies the character to find.
Start Optional. Specify where to start the search.

The return value of the PHP Strpos () function

The Strpos () function returns the position of the first occurrence of a string in another string, or FALSE if no string is found. The string position starts at 0, not starting from 1.

The functions associated with them are:

    • Stripos ()-finds the position of the first occurrence of a string in another string (case insensitive)

    • Strripos ()-Finds the last occurrence of a string in another string (case insensitive)

    • Strrpos ()-Finds the last occurrence of a string in another string (case-sensitive)

PHP Strpos () Function Example

Use the PHP strpos () function to find the location of the first occurrence of "PHP" in the string, with the following code:

<?phpecho Strpos ("You love php, I love php too!", "PHP"); >

The code runs the browser output result:

"Related articles recommended"

The definition and usage of PHP string function Stripos ()

PHP string Function Strripos () example

Detailed string function Strrpos ()

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.