Home > Backend Development > PHP Problem > How to delete a character in php

How to delete a character in php

藏色散人
Release: 2023-03-08 06:42:01
Original
2221 people have browsed it

php method to delete a character: first create a PHP sample file; then define a variable; then delete the last character through the "substr($str,0,strlen($str)-1);" method That’s it.

How to delete a character in php

The operating environment of this article: Windows 7 system, PHP version 5.6, DELL G3 computer.

php delete the last character

Original string 1,2,3,4,5,6,

Remove the last character", ", the final result is 1,2,3,4,5,6

Use the substr and strlen functions to achieve this.

Code:

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

Recommended: "PHP Video Tutorial"

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

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