Home >Backend Development >PHP Problem >How to remove the leftmost space in php

How to remove the leftmost space in php

藏色散人
藏色散人Original
2021-11-23 09:38:072148browse

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

How to remove the leftmost space in php

#The operating environment of this article: Windows7 system, PHP7.1, Dell G3 computer.

How to remove the leftmost space in php?

In PHP, you can use the ltrim function to remove the leftmost space.

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

Related functions:

rtrim() - Removes whitespace characters or other predefined characters on the right side of a string

trim() - Removes a string Whitespace characters or other predefined characters on both sides

Syntax

ltrim(string,charlist)

Parameters

string Required. Specifies the string to check.

charlist Optional. Specifies which characters are removed from a string. If this parameter is omitted, all the following characters are removed:

"\0" - NULL

"\t" - TAB

"\n " - Line feed

"\x0B" - Vertical tab character

"\r" - Carriage return

" " - Space

Remove spaces on the left side of the string:

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

HTML output of the above code (please view the source code):

<!DOCTYPE html>
<html>
<body>
不使用 ltrim:    Hello World!<br>使用 ltrim: Hello World!
</body>
</html>

Browser output of the above code:

不使用 ltrim: Hello World!
使用 ltrim: Hello World!

Recommended Study: "PHP Video Tutorial"

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