分析PHP函数explode如何将字符串转换为数组
我们在学习
1.PHP函数explode的格式如下:
array explode(string separator, string string,[int limit]);
2.参数中的separator为分隔符,string为待分割的字符串,limit为返回的数组中元素的最大个数。
PHP函数explode的具体使用实例:
- <?php
- $DOCUMENT_ROOT = $_SERVER[DOCUMENT_ROOT];
- ?>
- <html>
- <head>
- <title>Test Explode</title>
- </head>
- <body>
- <?php
- $peoples = file($DOCUMENT_ROOT./test/03/people.txt);
- $countcount = count($peoples);
- if ($count == 0) {
- echo NO peoples pending. Please try again later.;
- }
- for ($i = 0; $i < $count; $i++) {
- $line = explode(t, $peoples[$i]);
- echo <font color=red>.$line[0].</font>;
- echo <font color=blue>.$line[1].</font>;
- echo <font color=green>.$line[2].</font>;
- echo <br />;
- }
- ?>
- </body>
- </html>
希望广大学习爱好者们通过本文所介绍的PHP函数explode的使用示例,能够基本弄清PHP函数explode的使用方法。
教程网址:http://www.phprm.com/frame/php1003634.html
欢迎收藏∩_∩但请保留本文链接。