brad_tho
asked on
Str_replace and include() together
Hi, I have a document data.txt with csv data and each entry is on a new line.
When I include("data.txt"); all of the data is on one line...
and the following doesnt work either:
str_replace("\n","<br>",in clude("dat a.txt"));
Any ideas?
Thanks
When I include("data.txt"); all of the data is on one line...
and the following doesnt work either:
str_replace("\n","<br>",in
Any ideas?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
PHP also features a function called nl2br which replaces the newline character with the <br> element.
But rhickmott is right about include not being ideal for file access.
But rhickmott is right about include not being ideal for file access.
ASKER
<?php
$filename = 'data.txt';
$content = $_POST['procedure'] . "," . $_POST['date'] . "," . $_POST['start'] . "," . $_POST['finish'] . "," . $_POST['surgeon'] . "\r\n";
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($handle, $content) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($content) to file ($filename)!<br><br>
<html>
<head>
<title>
New Entry Submitted!
</title>
</head>
<body>
";
$file = file("data.txt");
foreach ($file as $value) {
echo("$value" . "<br>");
}
echo "
</body>
</html>
";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
?>