PHP strpos() Function

PHP strpos() Function is used to find the position of the first occurrence of a substring in a string. PHP strpos() function is PHP built-in function.

PHP Version : PHP 4, PHP 5, PHP 7, PHP 8

Syntax for strpos :

strpos(string $string, string $search, int $start);

Parameter,

$string : Required. It is the string to be searched.
$search : Required. It is value to search.
$start: Optional. It specifies where to begin the search. Search will start at the beginning of the string. If the $start is negative, the search will start at the end of the string.

Return values for strpos :

A strpos() Function returns the position of the first occurrence of a string inside another string. It also returns FALSE if the string is not found.  String positions always starts at 0.

The strpos() function is case-sensitive. You can also use stripos() Function for case-insensitive.

Let's see below example to understand php strpos() Function in details.

 

Example :

<?php
$str = "Learn php strpos function tutorial with example.";
echo "<br> Position at ".strpos($str,"tutorial");
?>

Output :

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

24943