PHP program code to delete the last character of a string_PHP tutorial

WBOY
Release: 2016-07-13 17:13:30
Original
678 people have browsed it

This is the simplest PHP introductory tutorial. We only need to know a few common functions to delete the last character of a string, such as substr, rtrim, etc.


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:

The function that comes with the system can achieve this effect, two methods:
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

Copy code

$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, ",")The above example only describes the use of PHP's own functions. We can also use many methods to achieve it. I won't go into details here. You can refer to the most basic PHP introductory tutorial. http://www.bkjia.com/PHPjc/629131.htmlwww.bkjia.com
true
http: //www.bkjia.com/PHPjc/629131.html
TechArticleThis is the simplest PHP introductory tutorial. We only need to know a few common functions to delete strings. The last character, if substr, rtrim, etc. Original string 1,2,3,...
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!