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
- / PostgreSQL 10 Bookings (ReadOnly) substr strtoupper str_shuffle
last run:
2024-07-06 13:55:36
10
- PHP 8.1 / MariaDB 11.4 extract var_dump substr bin2hex openssl_random_pseudo_bytes
last run:
2025-04-10 03:42:59
3
- PHP 7.4 / MariaDB 11.4 print_r str_repeat count array_merge substr
last run:
2025-02-12 11:49:30
3
- PHP 8.1 / MySQL 8.0 strpos substr
last run:
2023-04-25 14:55:07
3
- PHP 8.3 / MySQL 8.0 define base64_decode strtoupper trim str_replace strpos strlen substr openssl_encrypt base64_encode
last run:
2025-06-26 14:41:34
2
- PHP 8.4 / MySQL 8.0 substr strtolower
last run:
2025-05-16 22:42:56
2
- PHP 8.4 / MySQL 8.0 substr strtolower
last run:
2025-05-16 22:42:25
2
- PHP 8.4 / MySQL 8.0 substr md5
last run:
2025-03-24 09:10:26
2
- PHP 8.4 / MySQL 8.0 substr md5
last run:
2025-03-24 09:06:15
2
- PHP 8.4 / MariaDB 11.4 header preg_match substr strlen
last run:
2025-03-13 03:56:37
2
substr - New snippets
-
PHP 8.3 / MySQL 8.0 define base64_decode strtoupper trim str_replace strpos strlen substr openssl_encrypt base64_encode
added at:
2025-06-26 02:23:21
2
-
PHP 8.4 / MySQL 8.0 substr hex2bin strtolower openssl_decrypt
added at:
2025-06-21 04:15:46
1
-
PHP 8.4 / MySQL 8.0 substr hex2bin strtolower openssl_decrypt
added at:
2025-06-21 04:15:03
1
-
PHP 8.4 / MySQL 8.0 time substr md5
added at:
2025-06-17 06:12:03
1
-
PHP 7.4 / MySQL 8.0 substr log
added at:
2025-06-14 14:42:55
1
-
PHP 8.4 / MySQL 8.0 header base64_decode strrev str_rot13 strlen substr ord chr
added at:
2025-06-07 08:40:18
1
-
PHP 8.4 / MySQL 8.0 strval substr
added at:
2025-05-19 17:37:20
1
-
PHP 8.4 / MySQL 8.0 array_filter strlen strtolower substr array_map print_r
added at:
2025-05-16 23:23:15
1
-
PHP 8.4 / MySQL 8.0 array_filter strlen strtolower substr array_map print_r
added at:
2025-05-16 23:22:20
1
-
PHP 8.4 / MySQL 8.0 array_filter strtolower substr strlen array_map print_r
added at:
2025-05-16 23:20:59
1