程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> 分析PHP函數explode如何將字符串轉換為數組

分析PHP函數explode如何將字符串轉換為數組

編輯:關於PHP編程

我們在學習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 Explode</title> 
  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> 

希望廣大學習愛好者們通過本文所介紹的PHP函數explode的使用示例,能夠基本弄清PHP函數explode的使用方法。


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved