Home >Backend Development >PHP Problem >How to use php strpos function?

How to use php strpos function?

青灯夜游
青灯夜游Original
2019-05-30 13:33:452683browse

php The strpos() function is used to find the first occurrence of a string in another string (case sensitive). The syntax is strpos(string,find,start). If the string is not found, FALSE is returned.

How to use php strpos function?

php How to use the strpos() function?

The strpos() function finds the first occurrence of a string in another string (case-sensitive).

Syntax:

strpos(string,find,start)

Parameters:

● String: Required. Specifies the string to search for.

● Find: Required. Specifies the string to search for.

● Start: Optional. Specifies where to start the search.

Return value: Returns the position of the first occurrence of a string in another string, or returns FALSE if the string is not found.

Note: The strpos() function is case-sensitive; this function is binary safe.

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

Let’s take a look at how to use the php strpos() function through an example.

Example 1:

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

Output:

9

Example 2:

<?php
var_dump(strpos("You love php, I love php too!","PHP")) ;
?>

Output:

bool(false)

The above is the detailed content of How to use php strpos function?. 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