Home  >  Article  >  php教程  >  PHP explode() 字符串转换数组

PHP explode() 字符串转换数组

WBOY
WBOYOriginal
2016-06-13 11:19:371478browse

在php中要把字符串转换数组的方式有很多种,我们如果有规律性的可直接使用explode()函数来把字符串截成数组。  

定义和用法

explode() 函数把字符串分割为数组。

语法

explode(separator,string,limit)

例子

在本例中,我们将把字符串分割为数组:

 代码如下 复制代码

$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.
)

这样我们的字符就根据我们的设定就转换成了数组了哦。


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn