删除字符串左侧的字符:
<?php
$str = "Hello World!";
echo $str . "<br>";
echo ltrim($str,"Hello");
?>
亲自试一试 »
ltrim() 函数从字符串左侧删除空格或其他预定义字符。
相关功能:
ltrim(
string,charlist)
Parameter | Description |
---|---|
string | Required. Specifies the string to check |
charlist | Optional. Specifies which characters to remove from the string. If omitted, all of the following characters are removed:
|
返回值: | 返回修改后的字符串 |
---|---|
PHP 版本: | 4+ |
变更日志: | 这个字符列表PHP 4.1 中添加了参数 |
删除字符串左侧的空格:
<?php
$str = " Hello World!";
echo "Without ltrim: " . $str;
echo "<br>";
echo "With ltrim: " . ltrim($str);
?>
上述代码的 HTML 输出将是(查看源代码):
<!DOCTYPE html>
<html>
<body>
Without ltrim: Hello World!<br>With ltrim: Hello World!
</body>
</html>
上述代码的浏览器输出将是:
Without ltrim: Hello World!
With ltrim: Hello World!
亲自试一试 »
从字符串左侧删除换行符 (\n):
<?php
$str = "\n\n\nHello World!";
echo "Without ltrim: " . $str;
echo "<br>";
echo "With ltrim: " . ltrim($str);
?>
上述代码的 HTML 输出将是(查看源代码):
<!DOCTYPE html>
<html>
<body>
Without ltrim:
Hello World!<br>With ltrim: Hello World!
</body>
</html>
上述代码的浏览器输出将是:
Without ltrim: Hello World!
With ltrim: Hello World!
亲自试一试 »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!