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

分析PHP函数explode如何将字符串转换为数组

WBOY
Release: 2016-06-13 11:06:49
Original
1085 people have browsed it

我们在学习1.PHP函数explode的格式如下:

array explode(string separator, string string,[int limit]);

2.参数中的separator为分隔符,string为待分割的字符串,limit为返回的数组中元素的最大个数。

PHP函数explode的具体使用实例:

  1. php
  2. $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
  3. ?>
  4. html>
  5. head>
  6. title>Test Explodetitle>
  7. head>
  8. body>
  9. php
  10. $peoples = file($DOCUMENT_ROOT.'/test/03/people.txt');
  11. $countcount = count($peoples);
  12. if ($count == 0) {
  13. echo 'NO peoples pending. Please try again later.';
  14. }
  15. for ($i = 0; $i $count; $i++) {
  16. $line = explode("t", $peoples[$i]);
  17. echo 'font color=red>'.$line[0].'font>';
  18. echo 'font color=blue>'.$line[1].'font>';
  19. echo 'font color=green>'.$line[2].'font>';
  20. echo 'br />';
  21. }
  22. ?>
  23. body>
  24. html>
Copy after login

希望广大学习爱好者们通过本文所介绍的PHP函数explode的使用示例,能够基本弄清PHP函数explode的使用方法。


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
    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!