Use substr () to remove the last character of the string

Source: Internet
Author: User
Use substr () to remove the last character of the string
"," Must be used to separate the data in the statistical chart. However, when I use a loop to accumulate strings, it is inevitable that there will be one more ",". For example, delete the comma (,) at the end of the string to get, and 5.

"," Must be used to separate the data in the statistical chart. However, when I use a loop to accumulate strings, it is inevitable that there will be one more ",". For example, delete the comma (,) at the end of the string to get, and 5.Solution: Use the substr method of php. Syntax: string substr (string, int start, int [length]); parameter 1: Original string; parameter 2: start position of the cut; parameter 3: the truncation length. use $ newstr = substr ($ str, 0, strlen ($ str)-1) as follows, it is intercepted until the second to the last, so that the last "," is removed.

Related Article

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.