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 8.0 substr strrpos
added at:
2024-10-21 11:30:30
1
-
PHP 8.1 / MySQL 8.0 substr strrpos
added at:
2024-10-21 11:30:20
1
-
PHP 8.2.13 / MySQL 5.7 strtotime date substr
added at:
2024-10-10 23:36:27
1
-
PHP 8.1 / MySQL 8.0 strlen substr
added at:
2024-09-25 09:22:40
1
-
PHP 8.1 / MySQL 8.0 strlen substr trim
added at:
2024-09-25 09:12:57
1
-
PHP 8.1 / MySQL 5.7 str_split strpos str_pad decbin strlen chr bindec substr
added at:
2024-08-19 08:58:00
1
-
PHP 8.1 / MySQL 5.7 str_split strpos str_pad decbin strlen chr bindec substr
added at:
2024-08-19 08:57:45
1
-
PHP 8.1 / MySQL 5.7 str_split strpos str_pad decbin strlen chr bindec substr
added at:
2024-08-19 08:56:59
1
-
PHP 8.1 / MySQL 5.7 str_split strpos str_pad decbin ltrim strlen chr bindec substr strtoupper
added at:
2024-08-19 08:34:19
1
-
PHP 8.1 / MySQL 5.7 strlen str_split strpos str_pad decbin ltrim chr bindec substr strtoupper
added at:
2024-08-19 08:32:59
1