Fandom

PHP Wiki

Strpos

51pages on
this wiki
Add New Page
Talk0 Share

Description Edit

strpos will return the numeric position of a search string inside the given string. Note that the position in string starts with 0 and not with 1. If the optional offset parameter was set it starts searching at the character with that number. The return value will still be relative to the beginning of the string.

Note: strpos may return boolean false, but may also return a non-boolean value which evaluates to false, like 0 or an empty string (""). Use the === operator for testing the return value of this function.

Parameters Edit

{{{returns}}} strpos (string input, string search [, integer offset])

Parameter Infos Edit

Parameter PHP Version Type
strpos 4 or 5 returns integer
input 4 or 5 string
search 4 or 5 integer


Examples Edit

Example 1: The direct way Edit

<?php
 echo strpos("Find a string", "string");
?>

Output Edit

7


Example 2: Using a variable and offset Edit

<?php
 $string = "abcdef abcdef";
 $find   = "a";
 echo strpos($string, $find, 1); // Stars searching at the first b
?>

Output Edit

7


See also Edit

strrpos, stripos, strripos, strrchr, substr, stristr, strstr

For more details on this function, visit its entry in the php manual.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.