Home  >  Article  >  Backend Development  >  Detailed explanation of php strpos() function example

Detailed explanation of php strpos() function example

怪我咯
怪我咯Original
2017-06-08 15:51:356660browse

php What is the function of strpos() function?

strpos() function finds the first occurrence of a string within another string. It should be noted that this function is case-sensitive, contrary to the php stripos() function, which is not case-sensitive. This article will take you through the php strpos() function.

php strpos() function syntax

strpos(string,find,start)

Detailed explanation of parameters:

This function has three parameters, of which the first two parameters are required Yes, the third parameter is optional

Parameter Description
string Required. Specifies the string to be searched for.
find Required. Specifies the characters to search for.
start Optional. Specifies the location from which to start the search.

php The return value of strpos() function

strpos() function returns the first string in another string The position where the string appears first, or FALSE if the string is not found. String positions start at 0, not 1.

The related functions are:

  • stripos() - Find 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() - Find the last occurrence of a string in another string (case sensitive)

php strpos() function example

Use the php strpos() function to find the first occurrence of "php" in the string. The code is as follows:

Code Run the browser output result:

Detailed explanation of php strpos() function example

[Related article recommendations]

php Definition of string function stripos() And usage

Detailed explanation of php string function strripos() instance

Detailed explanation of string function strrpos()

The above is the detailed content of Detailed explanation of php strpos() function example. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn