I need help splitting the contents of a text file into an array. I tried using the split() function. However, that would not work because the file is already an array... Each line of the text file is: name,phonenumber,email,website I need to split each of the words between the commas into arrays. I don’t know how you would split the file contents if the contents is already in an array. For example I’ve got so far: $selectedfile = "./courses/".$_GET['course'].".txt"; $openfile = file($selectedfile); //this works $splitfile = split(",",$openfile); //this doesn’t. $openfile is already an array. Also, after I get each word of each line split into an array, how would I put the array contents into an HTML table. Would it be as simple as just doing: echo “<table>â€; foreach($arrayname as $tablearray) { echo “<tr><td>$tablearray</td></tr>†} echo “</table>†Thanks - Derek
You can do it like this: $selectedfile = "./courses/".$_GET['course'].".txt"; $openfile = file($selectedfile); //this works foreach ($openfile AS $line) { // name,phonenumber,email,website list($name, $phone, $email, $website) = explode(',', $line); echo "<tr><td>Name: {$name}</td></tr>\n"; // Etc... } PHP: