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.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 8.0 / MySQL 5.7 date strtotime substr print_r
last run:
2022-06-01 19:23:47
5
- PHP 8.1 / MySQL 5.7 strlen substr var_dump
last run:
2022-06-02 05:11:24
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 strlen substr var_dump
last run:
2022-05-14 07:30:20
4
- PHP 5 / MySQL 5.7 substr strlen
last run:
2021-04-10 15:10:18
4
- PHP 8.1 / MySQL 5.7 substr
last run:
2022-06-15 19:54:35
3
- PHP 8.1 / MySQL 5.7 dirname str_replace ltrim rtrim substr curl_init curl_setopt curl_exec curl_close
last run:
2022-06-14 00:56:17
3
- PHP 8.1 / MySQL 5.7 substr
last run:
2022-06-07 05:52:12
3
substr - New snippets
-
PHP 8.1 / MySQL 5.7 preg_replace substr array_map print_r
added at:
2022-06-23 08:51:10
1
-
PHP 8.1 / MySQL 5.7 preg_replace substr array_map print_r
added at:
2022-06-23 08:50:42
1
-
PHP 5 / MySQL 5.7 strtr trim preg_replace strtoupper substr strlen max print_r
added at:
2022-06-22 15:02:01
2
-
PHP 5 / MySQL 5.7 strtr trim preg_replace strtoupper substr strlen max print_r
added at:
2022-06-22 15:00:25
2
-
PHP 5 / MySQL 5.7 strtr trim preg_replace strtoupper substr print_r
added at:
2022-06-22 14:56:48
1
-
PHP 5 / MySQL 5.7 strtr trim preg_replace strtoupper substr print_r
added at:
2022-06-22 14:37:13
2
-
PHP 5 / MySQL 5.7 strtr trim preg_replace strtoupper substr print_r
added at:
2022-06-22 14:36:37
1
-
PHP 5 / MySQL 5.7 strtr trim preg_replace strtoupper substr print_r
added at:
2022-06-22 14:36:25
1
-
PHP 5 / MySQL 5.7 trim preg_replace strtoupper substr print_r
added at:
2022-06-22 14:34:27
1
-
PHP 8.1 / MySQL 5.7 substr
added at:
2022-06-15 19:52:42
3