the function "explode" doesn't work

0 MARTIN WANG · March 18, 2015
I just follow the tutorial and step by step but the result is not work.
I don't know if explode function didn't work or  commend <br> didn't work...
my result is always same like this:


Alex Billy Peter Daniel Dale Sandra

not like this:

Alex
Billy 
Peter
Daniel
Dale
Sandra

My code:


<?php
$filename='name.txt';
$handle=fopen($filename,'r');
$datain=fread($handle,filesize($filename));

$name_array=explode(',',$datain);

foreach($name_array as $name){
 echo $name.'<br>';
}
?>










Post a Reply

Replies

Oldest  Newest  Rating
+3 Mohamad Mirohamadi · March 18, 2015
The code is correct , maybe you miss something in name.txt file
your file should be like this: Alex,Billy,Peter,Daniel,Dale,Sandra
0 MARTIN WANG · March 19, 2015
Thanks bro.It works now:)
The problem is my name.txt file. 
  • 1

PHP

107,175 followers
About

Server-side, HTML embedded scripting language used to create dynamic Web pages.

Links
Moderators