How to remove the leftmost space in php

藏色散人
Release: 2023-03-14 06:02:01
Original
2142 people have browsed it

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

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

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

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

Browser output of the above code:

不使用 ltrim: Hello World!
使用 ltrim: Hello World!
Copy after login

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!

Related labels:
php
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