Home  >  Article  >  Backend Development  >  How to remove the last character in php

How to remove the last character in php

王林
王林Original
2020-08-12 15:00:481740browse

php method to remove the last character: We can use the rtrim() function to remove the last character. The rtrim() function is used to remove blank characters or other predefined characters on the right side of a string and return the modified string. The usage method is as follows: [rtrim($str,"World!");].

How to remove the last character in php

rtrim() function removes whitespace characters or other predefined characters on the right side of a string and returns the modified string.

(Recommended tutorial: php graphic tutorial)

Syntax:

rtrim(string,charlist)

Parameters:

  • string Required. Specifies the string to check.

  • #charlist Optional. Specifies which characters are removed from a string.

(Video tutorial recommendation: php video tutorial)

Code implementation:

<?php
$str = "Hello World!";
echo $str . "<br>";
echo rtrim($str,"World!");
?>

Output result:

Hello World!
Hello

The above is the detailed content of How to remove the last 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