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