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

What is the way to delete the last character in php

王林
Release: 2023-03-07 13:46:02
Original
2120 people have browsed it

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);
?>
Copy after login

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);
?>
Copy after login

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!

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