php函数str_split

<?php
print_r(str_split("Hello"));
// output:
/*
Array
(
[0] => H
[1] => e
[2] => l
[3] => l
[4] => o
)
*/

print_r(str_split("Hello",3));
// output:
/*
Array
(
[0] => Hel
[1] => lo
)
*/

 

字符串不是数组, 比如:

count('hello world')'  // output: 1

count(1231233);   //  output: 1

但是:

$str = 'hello world';

echo $str[0];    // output: h

 

将字符串转为数组, 就用函数str_split()吧

posted on 2012-05-24 21:37  DavidYanXW  阅读(210)  评论(0)    收藏  举报