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

Detailed explanation of php strpos() function example

怪我咯
Release: 2023-03-08 06:44:02
Original
6912 people have browsed it

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)
Copy after login

Detailed explanation of parameters:

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

ParameterDescription
stringRequired. Specifies the string to be searched for.
findRequired. Specifies the characters to search for.
startOptional. 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:

<?php
echo strpos("You love php, I love php too!","php");
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template