strpos
strpos — Find the position of the first occurrence of a substring in a string.Description
strpos( string $haystack,Find the numeric position of the first occurrence of needle in the haystack string.
string $needle,
int $offset = 0 ): int|false
Parameters
haystack
The string to search in.
needle
Prior to PHP 8.0.0, if needle is not a string, it is converted to an integer and applied as the ordinal value of a character. This behavior is deprecated as of PHP 7.3.0, and relying on it is highly discouraged. Depending on the intended behavior, the needle should either be explicitly cast to string, or an explicit call to chr() should be performed.
offset
If specified, search will start this number of characters counted from the beginning of the string. If the offset is negative, the search will start this number of characters counted from the end of the string.
Return Values
Returns the position of where the needle exists relative to the beginning of the haystack string (independent of offset). Also note that string positions start at 0, and not 1.Returns false if the needle was not found.
More information about strpos on official PHP documentation site
strpos - Popular snippets
- PHP 8.0 / MySQL 8.0 strpos
last run:
2023-05-10 04:12:51
11
- PHP 8.0 / MySQL 5.7 explode preg_match substr strpos
last run:
2022-02-11 21:10:03
11
- PHP 7.4 / MySQL 5.7 substr strpos
last run:
2023-06-28 11:01:30
8
- PHP 8.0 / MySQL 8.0 strtotime date strpos
last run:
2024-02-12 10:55:58
6
- PHP 8.0 / MySQL 8.0 strtotime date var_dump strpos
last run:
2024-02-12 11:08:11
5
- PHP 8.1 / MySQL 5.7 strpos parse_url parse_str
last run:
2023-06-23 05:25:00
5
- PHP 8.1 / MySQL 5.7 strpos
last run:
2023-04-28 17:51:10
5
- PHP 8.0 / MySQL 5.7 strpos strlen substr intval var_dump
last run:
2022-02-03 12:42:38
5
- PHP 8.1 / MySQL 5.7 strpos
last run:
2023-04-28 17:49:08
4
- PHP 8.1 / MySQL 5.7 ini_set strpos explode
last run:
2022-08-06 17:40:41
4
strpos - New snippets
-
PHP 8.2.13 / MySQL 5.7 explode trim strpos preg_replace implode file_get_contents
added at:
2024-03-17 01:52:39
1
-
PHP 8.1 / MySQL 5.7 explode trim strpos preg_replace implode file_get_contents
added at:
2024-03-17 01:52:31
2
-
PHP 8.0 / MySQL 5.7 strpos substr strlen
added at:
2024-03-05 10:57:47
1
-
PHP 8.1 / MySQL 5.7 strpos strlen
added at:
2024-03-03 05:51:51
2
-
PHP 8.1 / MySQL 5.7 strpos print_r
added at:
2024-03-02 10:10:31
1
-
PHP 8.1 / MySQL 5.7 strpos print_r
added at:
2024-03-02 10:10:03
2
-
PHP 8.1 / MySQL 5.7 strpos print_r
added at:
2024-03-02 10:09:55
1
-
PHP 8.1 / MySQL 5.7 strpos print_r
added at:
2024-03-02 10:09:20
1
-
PHP 8.1 / MySQL 5.7 strpos print_r
added at:
2024-03-02 10:08:59
1
-
PHP 8.1 / MySQL 5.7 strpos print_r
added at:
2024-03-02 10:08:15
1