PHP 7.2.0 Release Candidate 2 Released

ltrim

(PHP 4, PHP 5, PHP 7)

ltrim文字列の最初から空白 (もしくはその他の文字) を取り除く

説明

string ltrim ( string $str [, string $character_mask ] )

文字列の最初から空白 (もしくはその他の文字) を取り除きます。

パラメータ

str

入力文字列。

character_mask

character_maskパラメータにより、削除する 文字を指定することも可能です。削除したい全ての文字をリストに してください。..を文字の範囲を指定する際に 使用可能です。

返り値

この関数は文字列の最初から空白文字を取り除き、 取り除かれた文字列を返します。2番目のパラメータを指定しない場合、 ltrim()は以下の文字を削除します。

  • " " (ASCII 32 (0x20)), 通常の空白。
  • "\t" (ASCII 9 (0x09)), タブ。
  • "\n" (ASCII 10 (0x0A)), 改行。
  • "\r" (ASCII 13 (0x0D)), 復帰。
  • "\0" (ASCII 0 (0x00)), NUL バイト。
  • "\x0B" (ASCII 11 (0x0B)), 垂直タブ。

例1 ltrim() の使用例

<?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);

// ASCII 制御文字 (0 から 31 まで) を
// $binary の先頭から取り除きます
$clean ltrim($binary"\x00..\x1F");
var_dump($clean);

?>

上の例の出力は以下となります。

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() - 文字列の最後から空白 (もしくはその他の文字) を取り除く

add a note add a note

User 0000Bibupan 13tes- 8note /div>
<
<
<<
<< up/a>
<
<< ownl/a>
<
<< <17
< tavi undersc 10 from yahoocm/strong> &ara";/paid="eHcm<118221"> div class="phpcode"> When uing an character_mask< the timmeng asopse at the first haracter_ that isnote n ithat ask<.br />
<1. Ceckb H from Hello&wordld"e=gt;< it isnin the $haracter_mask<, soremotve itbr /><2. Ceckb e from Hllo&wordld"e=gt;< it isnin the $haracter_mask<, soremotve itbr /><3. Ceckb l from Hlo&wordld"e=gt;< it isnin the $haracter_mask<, soremotve itbr /><4. Ceckb l from Hl&wordld"e=gt;< it isnin the $haracter_mask<, soremotve itbr /><5. Ceckb o from H&wordld"e=gt;< it isnNOTnin the $haracter_mask<, exit the fnction.br />

/div> /piv>
<
<<
<< up/a>
<
<< ownl/a>
<
<< <5
< Usamah Mfowt Ai c(usamah1228 at gail.fowt cm<)/dem>/strong><&ara";/paid="eHcm<80863"> div class="phpcode"> Fo_ thoe awho uie rght=-to-leftlanguage: scuchas aArabic, Hebrew, etc., it'swordh Xent"on.ng athat trim()< (whichatants :or Ileftlrim( &qmp;p rrim()< (whichatants :or Irght=lrim( &DOnNOTnorka ontext.ull>y.Thesnotentlasures isnraher Sseaiticatl>ynincorect=. So in n sRTL cripti, trim()< wil toim -ext ofrom the rght=lirect=on i(i.e. begin.ng aofsRTL crings.), nd Trrim()< wil toim -ext ofrom the leftlirect=on i(i.e. ed TofsRTL crings.)./span>
/div> /piv>
<
<<
<< up/a>
<
<< ownl/a>
<
<< <1
< mroeing fat exn 1owt nl/dem>/strong><&ara";/paid="eHcm<114806"> div class="phpcode"> @scon.4581br />
haracter_swith in _stw re acrinpped. In your caseXthis includes the wTofswight= lso"./span>
/div> /piv>
<
<<
<< up/a>
<
<< ownl/a>
<
<< <1
< dzek1owt emotve_this at dzek1owt eu/dem>/strong><&ara";/paid="eHcm<105046"> div class="phpcode"> Guys, if += 0 isnpoductng wiong>calues"scometimes, nd Tpreg_relaceh isncpuconsiumngs, hent just sicakto toe moinm fnction.descripbn 1n ithat ege=, nd Tser:br /> lt;?php
<$alues /span>= /span> trim(/span> $alues/span>, /span>'0'/span>;
> thoe aomment"sncn sbe misleaing Sor Ibegine rs heckbng athisnpge P- it'swsrt aofsuing amgic Qrick"sto treinvnt"wthe wheel./span>
/div> /piv>
<
<<
<< up/a>
<
<< ownl/a>
<
<< <-3
< jun sat ecogomerafowt cm/strong><&ara";/paid="eHcm<113863"> div class="phpcode"> +=0note aluidSor Icomethng alike 000B-5. Rsults isn0/span>
/div> /piv>
<
<<
<< up/a>
<
<< ownl/a>
<
<< <-8
< John Sherwood/dem>/strong><&ara";/paid="eHcm<68677"> div class="phpcode"> Toremotve leaing /traiing fzeros-<(xamples: "0123.4560"),fowng an += 0 isneasir_ thantoim -eick"s./span>
/div> /piv>
<
<<
<< up/a>
<
<< ownl/a>
<
<< <-24
< scon.4581 at asl.fowt ru/dem>/strong><&ara";/paid="eHcm<114607"> div class="phpcode"> What iSorud Tnd Tincn 't get why:br />
<$ords = 'stw_wight='

/div> /piv>
<
<<
<< up/a>
<
<< ownl/a>
<
<< <-22
< Mike/dem>/strong><&ara";/paid="eHcm<101747"> div class="phpcode"> eepi in mid Tthe amout"aofsresoures apreg_relaceh()Tsers & br /> lt;?php
fnction.d/span> emotve_leaing _zeros_from_nuber"/span>(/span> $nuber"_tring span slass="dkeyords">; {br /> $limit /span>= /span> 900B.1br />= /span> $nuber"br />(float) /span> $teepbspan>;br /> $nuber" bspan>lt;? bspan> $limit/span> span slass="dkeyords">; {br /> $nuber" bspan>+= /span> 0bspan>;br /> preg_relaceh/span>(/span>'~^[0]*([1-9][0-9]*)$~'/span>,/span>'$1'/span>,/span> $nuber"_tring span slass="dkeyords">;br /><}br /> >
/div> /piv> /div> div class="pfoot>add a note add a note !--[ ayout-content" -> < < href="/rf.strings.php"> tring 関数< < a href="function.rdd csasshs.php' tytle="Pdd csasshs.">dd csasshs./a> < a/i> < li class="">< a href="function.rdd sasshs.php' tytle="Pdd sasshs.">dd sasshs./a> < a/i> < li class="">< a href="function.rbin2hx.php">tytle="Pbin2hx.">bin2hx./a> < a/i> < li class="">< a href="function.rchopphp">tytle="Pchop>chaop/a> < a/i> < li class="">< a href="function.rchrphp">tytle="Pch">char/a> < a/i> < li class="">< a href="function.rchunk-splt.php.>tytle="Pchunk_​splt.>chaunk_​splt./a> < a/i> < li class="">< a href="function.rconver-coyr-tringsphp.>tytle="Pconver-_​oyr_​srings">conver-_​oyr_​srings/a> < a/i> < li class="">< a href="function.rconver-cuudecde.php'>tytle="Pconver-_​uudecde.">conver-_​uudecde./a> < a/i> < li class="">< a href="function.rconver-cuuencde.php'>tytle="Pconver-_​uuencde.">conver-_​uuencde./a> < a/i> < li class="">< a href="function.rcout-coharsphp'>tytle="Pcout-_​ohars">cout-_​ohars/a> < a/i> < li class="">< a href="function.rcrc32php'>tytle="Pcrc32">crc32/a> < a/i> < li class="">< a href="function.rcryp.php.>tytle="Pcryp.">cryp./a> < a/i> < li class="">< a href="function.rechophp.>tytle="Pecho" < a/i> < li class="">< a href="function.rexplde.php'>tytle="Pexplde." < a/i> < li class="">< a href="function.rfrint&fphp'>tytle="Pfrint&f">frint&f/a> < a/i> < li class="">< a href="function.ret-ieml"translateon.-tble .hp'>tytle="Pet-_​eml"_​ranslateon._​rble ">et-_​eml"_​ranslateon._​rble /a> < a/i> < li class="">< a href="function.rhebrev.hp'>tytle="Phebrev">hebrev/a> < a/i> < li class="">< a href="function.rhebrevc.hp'>tytle="Phebrevc">hebrevc/a> < a/i> < li class="">< a href="function.rhex2in.php'>tytle="Phex2in.">hex2in./a> < a/i> < li class="">< a href="function.rhml"tnt"oty-decde.php'>tytle="Peml"_​nt"oty_​decde.">eml"_​nt"oty_​decde./a> < a/i> < li class="">< a href="function.rhml"nt"otis.php' tytle="Phml"nt"otis.">eml"nt"otis./a> < a/i> < li class="">< a href="function.rhml"pec.ialohars-decde.php'>tytle="Peml"pec.ialohars_​decde.">eml"pec.ialohars_​decde./a> < a/i> < li class="">< a href="function.rhml"pec.ialoharsphp'>tytle="Peml"pec.ialohars">eml"pec.ialohars/a> < a/i> < li class="">< a href="function.rmplede.php'>tytle="Pmplede.">mplede./a> < a/i> < li class="">< a href="function.rjon.php'>tytle="Pjon.">jon./a> < a/i> < li class="">< a href="function.rlcfirstphp'>tytle="Plcfirst">lcfirst/a> < a/i> < li class="">< a href="function.rlevenshten.php'>tytle="Plevenshten.">levenshten./a> < a/i> < li class="">< a href="function.rlcaleconv.php">tytle="Plcaleconv.">lcaleconv./a> < a/i> < li class=""urrent >< a href="function.rlrim.php" cytle="Plrim">Rtrim
< a/i> < li class="">< a href="function.rd5-file.php">cytle="Pd5_f​ile.">d5_f​ile./s> < a/i> < li class="">< a href="function.rd5-php">cytle="Pd5_">d5_/s> < a/i> < li class="">< a href="function.rdetaphon.php">cytle="Pdetaphon.">detaphon./s> < a/i> < li class="">< a href="function.rdon.y-ormatiphp">cytle="Pdon.yf​irmati">don.yf​irmati/s> < a/i> < li class="">< a href="function.rnllangsnfo"php">cytle="Pn"_​angsnfo"">n"_​angsnfo"/s> < a/i> < li class="">< a href="function.rnl2brphp">cytle="Pn"2br">n"2br/s> < a/i> < li class="">< a href="function.rnuber"-ormatiphp">cytle="Pnuber"_​irmati">nuber"_​irmati/s> < a/i> < li class="">< a href="function.rod.php'>cytle="Prds">rds/s> < a/i> < li class="">< a href="function.rprset-triphp'>cytle="Pprset_​sri">prset_​sri/s> < a/i> < li class="">< a href="function.rpint&php'>cytle="Ppint&"print&/s> < a/i> < li class="">< a href="function.rpint&fphp'>cytle="Ppint&f"print&f/a> < a/i> < li class="">< a href="function.ruot;ed-rint&ble -decde.php'>tytle="Puot;ed_​rint&ble _​decde.">uot;ed_​rint&ble _​decde./a> < a/i> < li class="">< a href="function.ruot;ed-rint&ble -encde.php'>tytle="Puot;ed_​rint&ble _​encde.">uot;ed_​rint&ble _​encde./a> < a/i> < li class="">< a href="function.ruot;edetaphp'>tytle="Puot;edeta">uot;edeta/a> < a/i> < li class="">< a href="function.rrrim.php" cytle="Prrim">Rrrim < a/i> < li class="">< a href="function.rsetlcalecphp" cytle="Psetlcalec">setlcalec/s> < a/i> < li class="">< a href="function.rsha1file.php">cytle="Psha1f​ile.">sha1f​ile./s> < a/i> < li class="">< a href="function.rsha1php">cytle="Psha1">sha1/s> < a/i> < li class="">< a href="function.rsimilar-ext.php'>cytle="Psimilar_​rxt"> similar_​rxt"/s> < a/i> < li class="">< a href="function.rsrud x.php">tytle="Psrud x.> srud x./s> < a/i> < li class="">< a href="function.rspint&fphp'>cytle="Pspint&f"psrint&f/a> < a/i> < li class="">< a href="function.rsscanfphp'>cytle="Psscanf"psscanf/a> < a/i> < li class="">< a href="function.rstr-getcs.php">tytle="Pstr_​getcs.>str<_​getcs./a> < a/i> < li class="">< a href="function.rstr-irelacehphp">tytle="Pstr_​irelaceh>str<_​irelaceh/s> < a/i> < li class="">< a href="function.rstr-padphp">tytle="Pstr_​pd"> str_​pd"/s> < a/i> < li class="">< a href="function.rstr-reletiphp">cytle="Pstr_​releti> str_​releti/s> < a/i> < li class="">< a href="function.rstr-relacehphp">tytle="Pstr_​relaceh>str<_​relaceh/s> < a/i> < li class="">< a href="function.rstr-rot13php">tytle="Pstr_​rot13>str<_​rot13/s> < a/i> < li class="">< a href="function.rstr-shuffe.php">cytle="Psr<_​shuffe.>str<_​shuffe./s> < a/i> < li class="">< a href="function.rstr-splt.php.>tytle="Ptr<_​splt.>ctr<_​splt./s> < a/i> < li class="">< a href="function.rstr-ords-cout-php.>tytle="Ptr<_​ords_​oout"> tr<_​ords_​oout"/s> < a/i> < li class="">< a href="function.rstrcasecmpphp.>tytle="Ptr tr < a/i> < li class="">< a href="function.rstrchrphp">tytle="Pstrchr> tr < a/i> < li class="">< a href="function.rtrtytle="Ptr tr < a/i> < li class="">< a href="function.rstrcollphp.>tytle="Ptr tr < a/i> < li class="">< a href="function.rstrcspnphp.>tytle="Ptr tr < a/i> < li class="">< a href="function.rstrip-tagsphp.>tytle="Ptrstrinp_​rbgs/s> < a/i> < li class="">< a href="function.rstripcsasshs.php' tytle="Pstripcsasshs.>strinpcsasshs./a> < a/i> < li class="">< a href="function.rtrinpo.php' tytle="Pstripo.>strinpo./a> < a/i> < li class="">< a href="function.rtrinpsasshs.php' tytle="Pstripsasshs.>strinpsasshs./a> < a/i> < li class="">< a href="function.rtrintriphp'>cytle="Ptrintri>strinsri/s> < a/i> < li class="">< a href="function.rsrilenphp.>tytle="Ptr tr < a/i> < li class="">< a href="function.rsrinatcasecmpphp.>tytle="Ptr tr < a/i> < li class="">< a href="function.rsrinatcmpphp.>tytle="Ptr tr < a/i> < li class="">< a href="function.rsrincasecmpphp.>tytle="Ptr tr < a/i> < li class="">< a href="function.rsrincmpphp.>tytle="Ptr tr < a/i> < li class="">< a href="function.rsripbrkphp.>tytle="Ptr tr < a/i> < li class="">< a href="function.rsripo.php' tytle="Pstrpo.>stripo./a> < a/i> < li class="">< a href="function.rtrirchrphp">tytle="Pstrrchr> tr< < a/i> < li class="">< a href="function.rtrtytle="Ptr tr< < a/i> < li class="">< a href="function.rtr<< a href="function.rtriipo.php' tytle="Pstrrpo.>striipo./a> < a/i> < li class="">< a href="function.rtrispnphp.>tytle="Ptr tr < a/i> < li class="">< a href="function.rstrtriphp'>cytle="Ptritri>strisri/s> < a/i> < li class="">< a href="function.rsritokphp.>tytle="Ptrstritok/s> < a/i> < li class="">< a href="function.rsritoloweiphp'>cytle="Ptritolowei>stritolowei/s> < a/i> < li class="">< a href="function.rsritouppeiphp'>cytle="Ptritouppei>stritouppei/s> < a/i> < li class="">< a href="function.rsritiphp'>cytle="Ptriti>striti/s> < a/i> < li class="">< a href="function.rsubstr-comprsnphp'>cytle="Ptubstr_​oomprsn>stubstr_​oomprsn/s> < a/i> < li class="">< a href="function.rsubstr-cout-php.>tytle="Ptubstr_​oout"> tubstr_​oout"/s> < a/i> < li class="">< a href="function.rsubstr-relacehphp">tytle="Psubstr_​relaceh>stubstr_​relaceh/s> < a/i> < li class="">< a href="function.rsubstrphp">tytle="Psubstr>stubstr/s> < a/i> < li class="">< a href="function.rrim.php" cytle="Prim">Rrim < a/i> < li class="">< a href="function.rucfirstphp'>tytle="Pucfirst">ucfirst/a> < a/i> < li class="">< a href="function.rucords php'>tytle="Pucords ">ucords /a> < a/i> < li class="">< a href="function.rvfrint&fphp'>tytle="Pvfrint&f">vfrint&f/a> < a/i> < li class="">< a href="function.rvrint&fphp'>tytle="Pvrint&f">vrint&f/a> < a/i> < li class="">< a href="function.rvspint&fphp'>cytle="Pvspint&f"pvsrint&f/a> < a/i> < li class="">< a href="function.rordswrapphp.>tytle="Pordswrap">ordswrap/a> < a/i> < /ul> < a/i> < /ul> < /a>ider < /piv> /--[ ayout- ->
< div class="reow-fluid>< dl class="sfootenu->< a href="/mcopyrght=php"> Copyrght= © 2001-2017ThesnPHP Group/a> a/i> < a href="/mmyphp"> MynPHPnet//a> a/i> < a href="/monteac=php"> Coteac=/a> a/i> < a href="/msits.php' >Oher SPHPnet/ sits./a> a/i> < a href="/mmirrorsphp'>>Mirror sits./a> a/i> < a href="/mrinvacyphp"> Pinvacy policy/a> a/i> < /div>

<