strpos() function in PHP

PHPProgrammingServer Side Programming

The strpos() function is used to find the position of first occurrence of a string inside another string.

Syntax

strpos(str, find, begin)

Parameters

  • str − The string to search

  • find − The string to find

  • begin − Where to begin the search

Return

The strpos() function returns the position of first occurrence of a string inside another string or else false if string is not found.

Example

The following is an example −

 Live Demo

<?php
   echo strpos("This is demo text !","demo");
?>

Output

The following is the output −

8

Example

Let us see another example −

 Live Demo

<?php
   $str = 'pqr pqr';
   $pos = strpos($str, 'p', 1);
   echo $pos;
?>

Output

The following is the output −

4
raja
Updated on 26-Dec-2019 09:22:34

Advertisements