substr
substr — Return part of a string.Description
substr( string $string, int $offset, ?int $length = null ): stringReturns the portion of string specified by the offset and length parameters.
Parameters
string
The input string.
offset
If offset is non-negative, the returned string will start at the offset'th position in string, counting from zero. For instance, in the string 'abcdef', the character at position 0 is 'a', the character at position 2 is 'c', and so forth.
If offset is negative, the returned string will start at the offset'th character from the end of string.
If string is less than offset characters long, false will be returned.
length
If length is given and is positive, the string returned will contain at most length characters beginning from offset (depending on the length of string).
If length is given and is negative, then that many characters will be omitted from the end of string (after the start position has been calculated when a offset is negative). If offset denotes the position of this truncation or beyond, false will be returned.
If length is given and is 0, false or null, an empty string will be returned.
If length is omitted, the substring starting from offset until the end of the string will be returned.
Return Values
Returns the extracted part of string; or false on failure, or an empty string.More information about substr on official PHP documentation site
substr - Popular snippets
- PHP 8.1 / MySQL 5.7 get_defined_vars substr printf
last run:
2023-10-31 14:43:12
15
- PHP 8.0 / MySQL 5.7 date strtotime substr print_r
last run:
2022-06-01 19:23:57
11
- PHP 8.0 / MySQL 5.7 explode preg_match substr strpos
last run:
2022-02-11 21:10:03
11
- PHP 5.6 / PostgreSQL 10 Bookings (ReadOnly) substr strtoupper str_shuffle
last run:
2024-07-06 13:55:36
10
- PHP 8.1 / MySQL 5.7 str_shuffle substr print_r
last run:
2022-11-13 07:45:54
10
- PHP 8.1 / MySQL 5.7 mb_strlen substr print_r
last run:
2023-08-17 14:09:17
9
- PHP 7.4 / MySQL 5.7 substr strpos
last run:
2023-06-28 11:01:30
8
- PHP 8.2.13 / MySQL 5.7 md5 explode substr
last run:
2023-06-15 08:30:51
8
- PHP 8.1 / MySQL 5.7 strlen substr strrev str_split
last run:
2023-12-12 04:17:41
5
- PHP 8.1 / MySQL 5.7 substr
last run:
2022-12-10 20:00:14
5
substr - New snippets
-
PHP 8.1 / MySQL 5.7 substr openssl_decrypt hex2bin var_dump
added at:
2024-12-19 09:23:12
1
-
PHP 8.1 / MySQL 5.7 substr openssl_decrypt hex2bin var_dump
added at:
2024-12-19 09:23:02
1
-
PHP 8.1 / MySQL 5.7 substr var_dump openssl_decrypt hex2bin
added at:
2024-12-19 09:22:14
1
-
PHP 8.1 / MySQL 5.7 substr var_dump openssl_decrypt hex2bin
added at:
2024-12-19 09:20:08
1
-
PHP 8.1 / MySQL 5.7 substr var_dump openssl_decrypt hex2bin
added at:
2024-12-19 09:19:56
1
-
PHP 8.1 / MySQL 5.7 preg_match substr strlen print_r
added at:
2024-12-11 21:35:59
1
-
PHP 8.1 / MySQL 5.7 preg_match substr strlen print_r
added at:
2024-12-11 21:35:52
1
-
PHP 8.1 / MySQL 5.7 preg_match substr strlen print_r
added at:
2024-12-11 21:35:08
1
-
PHP 8.1 / MySQL 5.7 preg_match substr strlen print_r
added at:
2024-12-11 21:34:52
1
-
PHP 8.1 / MySQL 5.7 preg_match substr strlen print_r
added at:
2024-12-11 21:34:07
2