我们先来看字符串转换成数组
str_split()
<?php
print_r(str_split("Hello"));
?>
Array
(
[0] => H
[1] => e
[2] => l
[3] => l
[4] => o
)
explode()
<?php
$str = "Hello world. It's a beautiful day.";
print_r (explode(" ",$str));
?>
结果
Array
(
[0] => Hello
[1] => world.
[2] => It's
[3] => a
[4] => beautiful
[5] => day.
)
preg_split()函数
代码如下 | 复制代码 |
<? $user_info = "+J+++G+++++w"; $fields = preg_split("/+{1,}/", $user_info); while ($x < sizeof($fields)) : print $fields[$x]. "<br>"; $x++; endwhile; ?> |
总结在php中str_split()、explode()函数功能是一样的,这里就不介绍了。
把数组转换在字符串
implode()
例
代码如下 | 复制代码 |
$array = array('a','b','c'); echo implode($array); //结果 abc |
时间: 2024-10-11 07:02:05