iconv_strpos()

iconv_strpos() — Finds position of first occurrence of a needle within a haystack.

Built-in function of PHP 8.5. The manual lists it as available in PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

Signature

iconv_strpos(string $haystack, string $needle, int $offset = 0, ?string $encoding = null): int|false

Parameters

ParameterTypeWhat it takes
$haystackstringThe entire string.
$needlestringThe searched substring.
$offsetintThe optional offset parameter specifies the position from which the search should be performed. If the offset is negative, it is counted from the end of the string.
$encoding?stringIf encoding parameter is omitted or null, string are assumed to be encoded in iconv.internal_encoding.

Return value

Returns the numeric position of the first occurrence of needle in haystack. If needle is not found, iconv_strpos() will return false. This function may return Boolean false, but may also return a non-Boolean value which evaluates to false. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.

Example

The PHP manual ships no example for iconv_strpos(); the signature and the parameter table above are the contract.

Changelog

VersionChange
8.0.0encoding is nullable now.
7.1.0Support for negative offsets has been added.

See also

strpos(), iconv_strrpos(), mb_strpos()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page iconv_strpos() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.