Home > php教程 > php手册 > body text

PHP explode() 字符串转换数组

WBOY
Release: 2016-06-13 11:19:37
Original
1477 people have browsed it

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

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


Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!