This question already has answers here:
PHP: Split string into array, like explode with no delimiter

(9个答案)


已关闭6年。




我正在寻找与php中的'this is a string'.split('')等效的方法。

如果我尝试$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
)

关于php - php explode 所有字符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9814375/

10-11 07:22