PHP str_split() 函數

實例

把字符串 "Shanghai" 分割到數組中:

<?php
print_r(str_split("Shanghai"));
?>

運行實例

定義和用法

str_split() 函數把字符串分割到數組中。

語法

str_split(string,length)
參數 描述
string 必需。規定要分割的字符串。
length 可選。規定每個數組元素的長度。默認是 1。

技術細節

返回值:

如果 length 小于 1,則 str_split() 函數將返回 FALSE。

如果 length 大于字符串的長度,則整個字符串將作為數組的唯一元素返回。

PHP 版本: 5+

更多實例

例子 1

使用 length 參數:

<?php
print_r(str_split("Shanghai",3));
?>

運行實例