PHPsubstr () function

Source: Internet
Author: User
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
  1. $ Str = 20100718-20100718
  2. $ Format_time = explode ("-", $ str );
  3. $ Time_str. = substr ($ format_time [0], 0, 4 )."-";
  4. $ Time_str. = substr ($ format_time [0], 4,2 )."-";
  5. $ Time_str. = substr ($ format_time [0], 6, 2 )."~ ";
  6. $ Time_str. = substr ($ format_time [1], 0, 4 )."-";
  7. $ Time_str. = substr ($ format_time [1], 4,2 )."-";
  8. $ Time_str. = substr ($ format_time [1], 6, 2 );
  9. Echo $ time_str; // 2010-07-18 ~ 2010-07-18

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.