Home  >  Article  >  Backend Development  >  How to delete a character in php

How to delete a character in php

藏色散人
藏色散人Original
2021-02-08 10:05:302074browse

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;

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!

Statement:
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