textfile to an array...any ideas?
<p>I am needing to turn a textfile into an array...I am not sure how to go about this because the other features ive seen for php take an entire file and put it into an array but not quite how I want it to be so I am looking for advice here..
The following is written in a textfile:
"jim kroi,richard wuu,yan kebler,justin persaud"</p>

<p>How can I use php to make an array where automatically a loop puts each name as an item of the array until all the names run out?</p>

<p>so the end result of what I am trying to do is:
$array= array("jim kroi","richard wuu","Yan kebler","justin persaud");</p>

<p>So a loop of some sort would basically search upto each comma and extract the name before it until all of the names run out....</p>

<p>There are some php substr and such functions but I cant quite think of how to do this..</p>

<p>Yes, I do have code, here it is:</p>

<pre><code>&lt;?php
error_reporting(-1);




$fp = fopen('numbers.csv', 'w');

fputcsv($fp, $_POST['names']); 
fputcsv($fp, $_POST['numbers']); 


fclose($fp);



?&gt;
</code></pre>

<p>i put them all in a csv but now how can I make 2 arrays, one with name the other with numbers? <a href="http://imageshack.us/photo/my-images/215/csv.png/" rel="nofollow">http://imageshack.us/photo/my-images/215/csv.png/</a></p>

<p>using implode I get the error:</p>

<p>Warning: implode() [function.implode]: Bad arguments. in C:\Program Files\xampp\htdocs\xampp\something.php on line 14</p>

<pre><code>&lt;?php
error_reporting(-1);

$myFile = "testFile.txt";


$fh = fopen($myFile, 'r'); // open file
$theData = fread($fh, 5); // read file and store in var
$array = explode("\n", $theData); // explode string by lines using \n
echo implode("&lt;br/&gt;", $theData); // put the array back together and show each item as a line
fclose($fh);


?&gt;
</code></pre>
