php 字串重要函數

來源:互聯網
上載者:User

標籤:char   htm   ring   sha   mit   nan   strong   style   split()   

1、chop()

從字串右端移除字元 

chop(string,charlist)

$str="hello world~";echo chop($str,"ld~");  //hello wor

ps.    charlist參數是可選的,如果不填,預設移除

  • "\0" - NULL
  • "\t" - 定位字元
  • "\n" - 換行
  • "\x0B" - 垂直定位字元
  • "\r" - 斷行符號
  • " " - 空格

 

2、chunk_split()

把字串分割為一連串更小的部分。

chunk_split(string,length,end)

$str="hello world~";echo chunk_split($str,1,".");  //h.e.l.l.o. .w.o.r.l.d.~.

 

3、explode()

把字串打散為數組。

explode(separator,string,limit)

$str="beijing,shanghai,nanjing,tianjing,anqing";print_r(explode(",",$str,3));     //Array ( [0] => beijing [1] => shanghai [2] => nanjing,tianjing,anqing )

ps. limit可選,規定所返回的數組元素的數目。

 

4、htmlspecialchars()

把預定義的字元轉換為 HTML 實體。

htmlspecialchars(string,flags,character-set,double_encode)

$str="hello <em>world</em>~";echo htmlspecialchars($str);       //hello <em>world</em>~
  • & (和號)成為 &
  • " (雙引號)成為 "
  • ‘ (單引號)成為 ‘
  • < (小於)成為 <
  • > (大於)成為 >

 

5、implode()    //別名為join()

返回由數組元素組合成的字串。

implode(separator,array)

$arr=array("shanghai,nanjing,beijing,tianjing,anqing");echo implode(" ",$arr);    //shanghai,nanjing,beijing,tianjing,anqing

ps. separator可選。規定數組元素之間放置的內容。預設是 ""(Null 字元串)。

 

6、lcfirst()

把字串中的首字元轉換為小寫。

lcfirst(string)

$arr="Hello world";echo lcfirst($arr);   //hello world

php 字串重要函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.