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

How to remove the last space in php

藏色散人
藏色散人Original
2021-07-12 09:20:101456browse

In PHP, you can use the rtrim function to remove the last space. The syntax is "rtrim(string,charlist)", and the parameter string specifies the string to be checked.

How to remove the last space in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How to remove the last space in php?

You can use the rtrim function to remove the last space. rtrim is to remove the right space of a string.

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

Related functions:

ltrim() - Removes whitespace characters or other predefined characters on the left side of the string

trim() - Removes both sides of the string White space characters or other predefined characters

Syntax

rtrim(string,charlist)

Parameters

string Required. Specifies the string to check.

charlist

Optional. Specifies which characters are removed from the string. If omitted, all of the following characters are removed:

"\0" - NULL

"\t" - Tab

"\n" - Newline

"\x0B" - vertical tab

"\r" - carriage return

" " - space

Return value: Return the modified character string.

Remove spaces on the right side of the string:

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

Recommended learning: "PHP Video Tutorial"

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