iconv_strpos
Description
The iconv_strpos of iconv for PHP finds the position of the first occurrence of a needle within a haystack.
Syntax
iconv_strpos( string $haystack, string $needle, int $offset = 0, ?string $encoding = null ): int|false
Parameters
haystack
The entire string.
If it is not a string, it is converted to a string and applied as the ordinal value of a character.
needle
The searched substring.
If it is not a string, it is converted to a string and applied as the ordinal value of a character.
offset
The 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
If encoding parameter is omitted or null, string are assumed to be encoded in iconv.internal_encoding.
Return
Returns the numeric position of the first occurrence of needle in haystack, false if the needle is not found.
WARNING: 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.
Examples
1 · haystack needle
<? $haystack = "haystack·haystack·haystack"; $needle = "·"; $return = iconv_strpos($haystack, $needle); echo $return; ?>
8
2 · offset
<? $haystack = "haystack·haystack·haystack"; $needle = "·"; $offset = 10; $return = iconv_strpos($haystack, $needle, $offset); echo $return; ?>
17
3 · encoding
<? $haystack = "haystack·haystack·haystack"; $needle = "·"; $offset = 10; $encoding = "ISO-8859-1"; $return = iconv_strpos($haystack, $needle, $offset, $encoding); echo $return; ?>
18