PHP ltrim() 函數(shù)
定義和用法
ltrim() 函數(shù)從字符串左側(cè)刪除空格或其他預(yù)定義字符。
語法
ltrim(string,charlist)
參數(shù) | 描述 |
---|---|
string | 必需。規(guī)定要轉(zhuǎn)換的字符串。 |
charlist |
可選。規(guī)定從字符串中刪除哪些字符。 如果未設(shè)置該參數(shù),則全部刪除以下字符:
|
例子
例子 1
<html>
<body>
<?php
$str = " Hello World!";
echo "Without ltrim: " . $str;
echo "<br />";
echo "With ltrim: " . ltrim($str)
;
?>
<body>
<html>
輸出:
Without ltrim: Hello World! With ltrim: Hello World!
如果在瀏覽器中查看源代碼,會看到以下 HTML:
<html> <body> Without ltrim: Hello World!<br />With ltrim: Hello World! </body> </html>
例子 2
<?php
$str = "\r\nHello World!";
echo "Without ltrim: " . $str;
echo "<br />";
echo "With ltrim: " . ltrim($str)
;
?>
輸出:
Without ltrim: Hello World! With ltrim: Hello World!
如果在瀏覽器中查看源代碼,會看到以下 HTML:
<html> <body> Without ltrim: Hello World!<br />With ltrim: Hello World! </body> </html>