How to remove the last character of a string in php

王林
Release: 2023-03-02 14:10:01
Original
2876 people have browsed it

The way PHP removes the last character from a string is through the substr() function. The substr() function can return a part of a string. Function syntax: [substr(string, start, length)], if it fails, it returns FALSE.

How to remove the last character of a string in php

php Deleting the last character of the string can be achieved through the substr() function and sublen() function.

(Recommended tutorial: php tutorial)

Related function introduction:

substr() function:

substr () function returns a portion of a string.

Syntax:

substr(string,start,length)
Copy after login

Return value:

Returns the extracted part of the string, returns FALSE if it fails, or returns an empty string.

Code implementation:

<?php
$str = "1,2,3,4,5,6,"; 
$newstr = substr($str,0,strlen($str)-1); 
echo $newstr; //echo 1,2,3,4,5,6
?>
Copy after login

The above is the detailed content of How to remove the last character of a string in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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