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

WBOY
Release: 2016-07-25 09:05:43
Original
2383 people have browsed it
When making statistical charts, you need to use "," to separate the data when fetching it. However, when I use a loop to accumulate strings, it is inevitable that there will be an extra "," in the end. For example, I took out 1,2,3,4,5, but I need to delete the comma at the end of the string to get 1,2,3,4,5.

When making statistical charts, you need to separate the data with "," when extracting it. However, when I use a loop to accumulate strings, it is inevitable that there will be an extra "," in the end. For example, I took out 1,2,3,4,5, but I need to delete the comma at the end of the string to get 1,2,3,4,5. Solution: Using php’s substr method, Syntax: string substr(string string, int start, int [length]); Parameter 1: original string; Parameter 2: starting position of cutting; Parameter 3: intercepted length; Use it like this: $newstr = substr($str,0,strlen($str)-1); Cut from the beginning to the penultimate digit, thus removing the last ",".



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!