php array / format issue reading text file with text area

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
iancampbe
Forum Newbie
Posts: 2
Joined: Tue Apr 01, 2008 8:49 pm

php array / format issue reading text file with text area

Post by iancampbe »

I am new to PHP. I have made a form where a user inputs details. This is read/appended to a text file when submitted.

**** PLEASE USE THE CODE TAG WHEN POSTING *****

Code: Select all

$myFile = "details.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = $fname. "\t".$lname. "\t".$phone. "\t".$positiontype. "\t".$details. "\t".$education. "\t".$TofD."\n";
fwrite($fh, $stringData);
fclose($fh);
I have a form that explodes the results from that txt file into a table. It all seemed to work fine, but I have noticed if someone enters a line in the text area (details), and presses enter and puts in another line..whilst all looks fine in the .txt file, when I read it using code below onto a new screen, it splits the text area into different cells, destroying the table.

If the input in the text area is typed all as one sentence, I dont have this problem.

Can anyone help???

Code: Select all

echo "<table border=1 bgcolor = \"#000000\" bordercolor = \"#333333\"> \n";
echo "<tr><th>First Name</td>
     <th>Surname</td>
     <th>Phone No</td>
     <th>Position Type</td>
     <th>Details</td>
     <th>Education</td>
     <th>Time of Day to Contact</td>    
      </tr>";
for ($i=0; $i<$number_posts; $i++)
{   
//split the lines
$line = explode ( "\t", $test[$i] );
echo "<tr><td>$line[0]</td>
    <td>$line[1]</td>
    <td>$line[2]</td>
    <td>$line[3]</td>
    <td>$line[4]</td>
    <td>$line[5]</td>
    <td>$line[6]</td>
</tr>";
}
echo "</table>";
?>
iancampbe
Forum Newbie
Posts: 2
Joined: Tue Apr 01, 2008 8:49 pm

Re: php array / format issue reading text file with text area

Post by iancampbe »

Ive worked it out now...no worries...str_replace
Post Reply