Home > Backend Development > PHP Problem > What are the functions in php that can remove spaces?

What are the functions in php that can remove spaces?

王林
Release: 2023-03-04 19:24:01
Original
3100 people have browsed it

The functions in php that can remove spaces are: 1. ltrim(), this function can remove spaces at the beginning of a string; 2. rtrim(), this function can remove spaces at the end of a string; 3. , trim(), this function can remove spaces at the beginning and end of a string.

What are the functions in php that can remove spaces?

#ltrim function removes spaces or other characters at the beginning of a string.

(Recommended tutorial: php graphic tutorial)

Syntax:

string ltrim(string $str [,string $charlist])
Copy after login

Description: charlist specifies which characters to delete from the string. If this parameter is omitted by default, all the following characters

What are the functions in php that can remove spaces?

are removed. Example:

$str = "\n\n\t\tABC\t\t";
echo ltrim($str);
//输出后,ABC前面的空白就没有了
Copy after login

rtrim function removes spaces or other characters at the end of a string.

(Video tutorial recommendation: php video tutorial)

Syntax:

string rtrim(string $str[,string $charlist])
Copy after login

trim function to delete spaces or other spaces at the beginning and end of a string character.

Grammar:

string trim(string $str[,string $charlist])
Copy after login

Example:

<?php
$str = &#39;Demon is an English teacher.17847564092&#39;;
$str = rtrim($str,&#39;0..9&#39;);
echo $str;
//删除末尾多余的数字
Copy after login

The above is the detailed content of What are the functions in php that can remove spaces?. 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