我們在學習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的使用方法。