Home > php教程 > php手册 > php去掉字符串的最后一个字符

php去掉字符串的最后一个字符

WBOY
Release: 2016-06-13 10:49:39
Original
1031 people have browsed it

原字符串1,2,3,4,5,6,
去掉最后一个字符",",最终结果为1,2,3,4,5,6
代码如下:

$str = "1,2,3,4,5,6,";
$newstr = substr($str,0,strlen($str)-1);
echo $newstr; 
//echo 1,2,3,4,5,6
 
系统自带的函数即可实现这样的效果,两种方法:
1) substr($str, 0, -1)
2)rtrim($str, ",")

 


摘自 〃Style ひぐ

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template