Line breaking on textfields, how to you fix this?
Posted: Sat Apr 16, 2005 1:04 pm
Hi, Ill explain my current setup before i describe the problem.
Im running a web form in html which is processing that data via submit.php which posts the data into a text file which is subsequently read back into a data.php file.
The problem is this:
When a user creates a new line in a text file this doesnt seem to be picked up and stored in the txt file and so the text just spans across the page. Can anybody help?
heres my submit.php code
my submit code is a little messy but its the first time ive coded in this language. Unfortuantely my limitations are that i cant use sql databases and has to run as a flat file system via txt files.
thank you very much
Ari :.
Im running a web form in html which is processing that data via submit.php which posts the data into a text file which is subsequently read back into a data.php file.
The problem is this:
When a user creates a new line in a text file this doesnt seem to be picked up and stored in the txt file and so the text just spans across the page. Can anybody help?
heres my submit.php code
Code: Select all
<?php
include("header.inc");
//writing data to log
{
$TimeFrame = $_POST['TimeFrame'];
$filename = "data.txt"; // File which holds all data
$content = "<b>$TimeFrame\n</b>"; // Content to write in the data file
$fp = fopen($filename, "a"); // Open the data file, file points at the end of file
$fw = fwrite( $fp, $content ); // Write the content on the file
}
$Time = $_POST['Time'];
if(!$Time) // If time scale isnt entered show error message
{
echo "Please enter a time scale.";
exit;
}
else
{
$filename = "data.txt"; // File which holds all data
$content = "$Time\n<br>"; // Content to write in the data file
$fw = fwrite( $fp, $content ); // Write the content on the file
}
// Promotional text and message and percent
{
$promotionaltxt = $_POST['promotionaltxt'];
$filename = "data.txt"; // File which holds all data
$content = "<br><b>$promotionaltxt\n</b>"; // Content to write in the data file
$fw = fwrite( $fp, $content ); // Write the content on the file
}
{
$Promo = $_POST['Promo'];
$filename = "data.txt"; // File which holds all data
$content = "$Promo\n<br>"; // Content to write in the data file
$fw = fwrite( $fp, $content ); // Write the content on the file
}
{
$Promotional = $_POST['Promotional'];
$filename = "data.txt"; // File which holds all data
$content = "<br>$Promotional\n<br>"; // Content to write in the data file
$fw = fwrite( $fp, $content ); // Write the content on the file
}
// ending promotional element field data input
// starting large projects data field
{
$largeprojectstxt = $_POST['largeprojectstxt'];
$filename = "data.txt"; // File which holds all data
$content = "<br><b>$largeprojectstxt\n</b>"; // Content to write in the data file
$fw = fwrite( $fp, $content ); // Write the content on the file
}
{
$LProject = $_POST['LProject'];
$filename = "data.txt"; // File which holds all data
$content = "$LProject\n<br>"; // Content to write in the data file
$fw = fwrite( $fp, $content ); // Write the content on the file
}
{
$LargeProjects = $_POST['LargeProjects'];
$filename = "data.txt"; // File which holds all data
$content = "<br>$LargeProjects\n<br>"; // Content to write in the data file
$fw = fwrite( $fp, $content ); // Write the content on the file
}
//end large projects
//start admin data fields
{
$admintxt = $_POST['admintxt'];
$filename = "data.txt"; // File which holds all data
$content = "<br><b>$admintxt\n</b>"; // Content to write in the data file
$fw = fwrite( $fp, $content ); // Write the content on the file
}
{
$AdminPercent = $_POST['AdminPercent'];
$filename = "data.txt"; // File which holds all data
$content = "$AdminPercent\n<br>"; // Content to write in the data file
$fw = fwrite( $fp, $content ); // Write the content on the file
}
{
$Admin = $_POST['Admin'];
$filename = "data.txt"; // File which holds all data
$content = "$Admin\n<br><br><br><br>"; // Content to write in the data file
$fp = fopen($filename, "a"); // Open the data file, file points at the end of file
$fw = fwrite( $fp, $content ); // Write the content on the file
// Function to breakup log words in message -------------------------
function wordbreak($text, $wordsize) {
if (strlen($text) <= $wordsize) { return $text; } # No breaking necessary, return original text.
$text = str_replace("\n", "", $text); # Strip linefeeds
$done = "false";
$newtext = "";
$start = 0; # Initialize starting position
$segment = substr($text, $start, $wordsize + 1); # Initialize first segment
while ($done == "false") { # Parse text
$lastspace = strrpos($segment, " ");
$lastbreak = strrpos($segment, "\r");
if ( $lastspace == "" AND $lastbreak == "" ) { # Break segment
$newtext .= substr($text, $start, $wordsize) . " ";
$start = $start + $wordsize; }
else { # Move start to last space or break
$last = max($lastspace, $lastbreak);
$newtext .= substr($segment, 0, $last + 1);
$start = $start + $last + 1;
} # End If - Break segment
$segment = substr($text, $start, $wordsize + 1);
if ( strlen($segment) <= $wordsize ) { # Final segment is smaller than word size.
$newtext .= $segment;
$done = "true";
} # End If - Final segment is smaller than word size.
} # End While - Parse text
$newtext = str_replace("\r", "\r\n", $newtext); # Replace linefeeds
return $newtext;
} # End of function - Word Break
fclose( $fp ); // Close the file after writing
if(!$fw) echo "Couldn't write the entry.";
else echo "Your entry has been successful";
}
?>
<?php
include("footer.inc");
?>thank you very much
Ari :.