PHP 字符串 ltrim() 函數是預定義的函數。它通常用於刪除字符串兩側的空格或字符串左側的其他字符。
用法:
ltrim(string,charlist);
參數 | 描述 | 必需/可選 |
---|---|---|
String | 指定要檢查的字符串。 | Required |
charlist | 指定要從字符串中刪除的字符。
|
Optional |
例子1
<?php
$str = " Hello PHP!";
echo "Without ltrim() Function:" . $str;
echo "<br>";
echo "With ltrim() function:" . ltrim($str);
?>
輸出:
Without ltrim() Function:Hello PHP! With ltrim() function:Hello PHP!
例子2
<?php
$str = "Hello PHP Javatpoint!";
echo "Without ltrim() Function:" . $str;
echo "<br>";
echo "With ltrim() function:" . ltrim($str);
?>
輸出:
Without ltrim() Function:Hello PHP Javatpoint! With ltrim() function:Hello PHP Javatpoint!
例子3
<?php
$str = "\n\n\nHello PHP!";
echo "Without ltrim() funcion:" . $str;
echo "<br>";
echo "With ltrim() function:" . ltrim($str);
?>
輸出:
Without ltrim():Hello World! With ltrim:Hello World!
注意:要從字符串的左側刪除換行符,我們可以使用 (\n):
相關用法
- PHP string lcfirst()用法及代碼示例
- PHP string levenshtein()用法及代碼示例
- PHP string rtrim()用法及代碼示例
- PHP string printf()用法及代碼示例
- PHP string ord()用法及代碼示例
- PHP string join()用法及代碼示例
- PHP string sha1()用法及代碼示例
- PHP string setlocale()用法及代碼示例
- PHP string sha1_file()用法及代碼示例
- PHP string md5()用法及代碼示例
- PHP string str_repeat()用法及代碼示例
- PHP string str_shuffle()用法及代碼示例
- PHP string similar_text()用法及代碼示例
- PHP string crypt()用法及代碼示例
- PHP string str_ireplace()用法及代碼示例
- PHP string str_split()用法及代碼示例
- PHP string strcoll()用法及代碼示例
- PHP string str_rot13()用法及代碼示例
- PHP string str_pad()用法及代碼示例
注:本文由純淨天空篩選整理自 PHP string ltrim() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。