Time truncation (a friend with better suggestions can post it) is optional. Specifies the length of the string to be returned. The default value is until the end of the string.
Syntax
Substr (string, start, length)
Parameters |
Description |
String |
Required. Specifies that a part of the string is to be returned. |
Start |
Required. Specifies where the string starts.
- Positive number-start at the specified position of the string
- Negative number-starting from the specified position at the end of the string
- 0-start at the first character in the string
|
Charlist |
Optional. Specifies the length of the string to be returned. The default value is until the end of the string.
- Positive number-return from the position of the start parameter
- Negative number-return from the end of the string
|
Instance:
Time truncation (a friend with better suggestions can post it)
PHP code
- $ Str = 20100718-20100718
- $ Format_time = explode ("-", $ str );
- $ Time_str. = substr ($ format_time [0], 0, 4 )."-";
- $ Time_str. = substr ($ format_time [0], 4,2 )."-";
- $ Time_str. = substr ($ format_time [0], 6, 2 )."~ ";
- $ Time_str. = substr ($ format_time [1], 0, 4 )."-";
- $ Time_str. = substr ($ format_time [1], 4,2 )."-";
- $ Time_str. = substr ($ format_time [1], 6, 2 );
- Echo $ time_str; // 2010-07-18 ~ 2010-07-18