php 字串分割函數split

來源:互聯網
上載者:User

標籤:php 字串分割函數split

說明

  array split    ( string $pattern   , string $string   [, int $limit  ] )
 

本函數返回一個字串數組,每個單元為   string 經區分大小寫Regex   pattern 作為邊界分割出的子串。如果設定了   limit,則返回的數組最多包含   limit 個單元,而其中最後一個單元包含了   string 中剩餘的所有部分。如果出錯,則   split() 返回 FALSE。

   

Example #1 split() 例子

<?php
list($user, $pass, $uid, $gid, $extra) =
    
split (":", $passwd_line, 5);
?>
   
     

如果字串中有 n 個與   pattern 匹配的項目,則返回的數組將包含   n+1 個單元。例如,如果沒有找到   pattern,則會返回一個只有一個單元的數組。當然,如果   string 為空白也是這樣。


Example #2 split() 例子

<?php
// 分隔字元可以是斜線,點,或橫線
$date = "04/30/1973";
list(
$month, $day, $year) = split (‘[/.-]‘, $date);
echo 
"Month: $month; Day: $day; Year: $year<br />";
?>
   
     


注意 pattern   是一個Regex。如果想要用的分割字元是Regex中的特殊字元,要先將其轉義。


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.