Home > Backend Development > PHP Tutorial > PHP removes the last character from a string_PHP tutorial

PHP removes the last character from a string_PHP tutorial

WBOY
Release: 2016-07-13 17:51:29
Original
962 people have browsed it

Original string 1,2,3,4,5,6,
Remove the last character "," and the final result is 1,2,3,4,5,6
The code is as follows:

$str = "1,2,3,4,5,6,";
$newstr = substr($str,0,strlen($str)-1);
echo $newstr;
//echo 1,2,3,4,5,6

The function that comes with the system can achieve this effect, two methods:
1) substr($str, 0, -1)
2)rtrim($str, ",")


Excerpted from 〃Style ひぐ

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478188.htmlTechArticleOriginal string 1,2,3,4,5,6, remove the last character, and the final result is 1,2,3,4,5,6 The code is as follows: $str = 1,2,3,4,5,6,; $newstr = substr($str,0,strlen($str)-1); echo $newstr; //echo 1...
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