Home  >  Article  >  Backend Development  >  What is the way to delete the last character in php

What is the way to delete the last character in php

王林
王林Original
2020-11-09 11:18:212096browse

How to delete the last character in php: You can use the rtrim function to delete, such as [rtrim($str)]. The rtrim function can remove whitespace characters or other predefined characters on the right side of a string and return the modified string.

What is the way to delete the last character in php

Function used:

rtrim() function removes blank characters or other predefined characters on the right side of the string and returns Modified string.

(Learning video recommendation: java video tutorial)

Example:

Remove spaces on the right side of the string:

<?php
$str = "Hello World!    ";
echo "不使用 rtrim:" . $str;
echo "<br>";
echo "使用 rtrim:" . rtrim($str);
?>

Remove the newline character (\n) on the right side of the string:

<?php
$str = "Hello World!\n\n\n";
echo "不使用 rtrim:" . $str;
echo "<br>";
echo "使用 rtrim:" . rtrim($str);
?>

Related recommendations: php training

The above is the detailed content of What is the way to delete 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