php php爆炸所有字符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9814375/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 07:40:34  来源:igfitidea点击:

php explode all characters

phparraysexplode

提问by qwertymk

I'm looking for the equivalent of what in js would be 'this is a string'.split('')for PHP.

我正在寻找相当于 js'this is a string'.split('')中 PHP 的内容。

If I try $array = explode('', 'testing');I get an error Warning: explode() [function.explode]: Empty delimiter in

如果我尝试$array = explode('', 'testing');我得到一个错误Warning: explode() [function.explode]: Empty delimiter in

Is there another way to do this?

有没有另一种方法可以做到这一点?

回答by Josh

As indicated by your error, exploderequires a delimiter to split the string. Use str_splitinstead:

如您的错误所示,explode需要一个分隔符来拆分字符串。使用str_split来代替:

$arr = str_split('testing');

Output

输出

Array
(
    [0] => t
    [1] => e
    [2] => s
    [3] => t
    [4] => i
    [5] => n
    [6] => g
)

回答by nickb

Use the str_splitfunction.

使用该str_split功能。

$array = str_split( 'testing');

回答by Mark Roach

$string = "TEST";

echo $string[0];  // This will display T

There is no need to explode it

没必要炸

回答by user3470929

TO SPLIT string into ARRAY its best to use

TO SPLIT string into ARRAY 最好用

$arr= str_split($string);