string_strpos() Function

  • PHP strpos() function search for the required text in a string.
  • If a match is found, the function returns the character position of the first match. If no match is found, it will return FALSE.
  • The given example shows the use of PHP strpos() function:
<!DOCTYPE html>

<html>

<body>

<?php

echo strpos("www.eitworld.com", "world");

echo "<br>";

echo strpos("Popular Tutorial", "Tutorial");

echo "<br>";

echo strpos("PHP Tutorial", "PHP");

?>

</body>

</html>

Output

string
    In the above example:
  • In first string www.eitworld.com world is present at position 7 that's why strpos() function returns 7.
  • In Second string Popular Tutorial Tutorial is present at position 8 that's why strpos() function returns 8.
  • In Third string PHP TutorialPHP is present at position 0 that's why strpos() function returns 0.