【发布时间】:2012-04-06 13:08:40
【问题描述】:
我正在寻找与 js 中的 'this is a string'.split('') 对应的 PHP。
如果我尝试$array = explode('', 'testing');,我会收到错误Warning: explode() [function.explode]: Empty delimiter in
还有其他方法吗?
【问题讨论】:
我正在寻找与 js 中的 'this is a string'.split('') 对应的 PHP。
如果我尝试$array = explode('', 'testing');,我会收到错误Warning: explode() [function.explode]: Empty delimiter in
还有其他方法吗?
【问题讨论】:
如您的错误所示,explode 需要分隔符来拆分字符串。请改用str_split:
$arr = str_split('testing');
输出
Array
(
[0] => t
[1] => e
[2] => s
[3] => t
[4] => i
[5] => n
[6] => g
)
【讨论】:
使用str_split 函数。
$array = str_split( 'testing');
【讨论】:
$string = "TEST";
echo $string[0]; // This will display T
不用炸了
【讨论】:
strlen 上循环 for。
TO SPLIT string into ARRAY 最好用
$arr= str_split($string);
【讨论】: