PHP 中的 ltrim() 函数
phpprogrammingserver side programming更新于 2025/8/9 6:37:17
ltrim() 函数用于从字符串开头去除空格或其他字符。
语法
ltrim(str, charlist)
参数
str − 待检查的字符串
charlist − 指定要从字符串中删除的字符。如果未指定参数,则删除字符串后面的所有字符。
"\0 − NULL
"\t" 减去制表符
"
" 减去换行符"\x0B" 减去垂直制表符
"\r" 减去回车符
" " 减去普通空格
返回
ltrim() 函数返回修改后的字符串。
示例
下面是一个例子 −
<?php $s = " Welcome!"; echo "Without ltrim = " . $s; echo "<br>"; echo "With ltrim = " . ltrim($s); ?>
输出
Without ltrim = Welcome! With ltrim = Welcome!
示例
下面是一个例子 −
<?php $string = " website"; echo "Welcome to the ".ltrim($string); ?>
输出
Welcome to the website

