首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

ltrim

(PHP 4, PHP 5, PHP 7)

ltrim - 从字符串的开头去除空格(或其他字符)

描述

代码语言:javascript
复制
string ltrim ( string $str [, string $character_mask ] )

从字符串的开头去掉空格(或其他字符)。

参数

str

输入字符串。

character_mask

您还可以通过character_mask参数指定要去除的字符。 只需列出您想要剥离的所有角色。 用..你可以指定一个字符范围。

返回值

这个函数返回一个字符串,从str的开头剥离空白字符。 没有第二个参数,ltrim()会去掉这些字符:

  • “”(ASCII 320x20)),一个普通的空间。
  • “\ t”(ASCII 90x09)),一个选项卡。
  • “\ n”(ASCII 100x0A)),换行(换行)。
  • “\ r”(ASCII 130x0D)),回车。
  • “\ 0”(ASCII 00x00)),NUL字节。
  • “\ x0B”(ASCII 110x0B)),一个垂直标签。

例子

示例#1 ltrim()的使用示例

代码语言:javascript
复制
<?php

$text?=?"\t\tThese?are?a?few?words?:)?...??";
$binary?=?"\x09Example?string\x0A";
$hello??=?"Hello?World";
var_dump($text,?$binary,?$hello);

print?"\n";


$trimmed?=?ltrim($text);
var_dump($trimmed);

$trimmed?=?ltrim($text,?"?\t.");
var_dump($trimmed);

$trimmed?=?ltrim($hello,?"Hdle");
var_dump($trimmed);

//?trim?the?ASCII?control?characters?at?the?beginning?of?$binary
//?(from?0?to?31?inclusive)
$clean?=?ltrim($binary,?"\x00..\x1F");
var_dump($clean);

?>

上面的例子将输出:

代码语言:javascript
复制
string(32) "        These are a few words :) ...  "
string(16) "    Example string
"
string(11) "Hello World"

string(30) "These are a few words :) ...  "
string(30) "These are a few words :) ...  "
string(7) "o World"
string(15) "Example string
"

扩展内容

  • trim() - 从字符串的开头和结尾去除空白字符(或其他字符)
  • rtrim() - 从字符串的末尾去除空格(或其他字符)

← localeconv

md5_file →

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com