Home > php教程 > php手册 > php删除字符串最后一个字符程序代码

php删除字符串最后一个字符程序代码

WBOY
Release: 2016-06-13 10:14:53
Original
909 people have browsed it

这个算是最简单的php入门教程了,我们只要知道几个常用的函数就可以实现删除字符串最后一个字符了,如果substr,rtrim等。


原字符串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, ",")

上面的实例只讲述了利用php自身的函数,我们还可以利用很多的方法来实现了,这里就不说多了最基本的php入门教程大可参考一下。

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