Remove Carriage Returns from textarea Input [SOLVED]
Posted: Sat Mar 19, 2005 9:46 pm
[EDIT] Not solved anymore! The text is still not being cleaned. The returns are still left... Damn this really bits. Strangly enough I'm not sure what is going on. The file becomes borked such as
I need the entire message to be on one line. (line 3)
[/EDIT]
This has been bothering me a lot. I'm building a simple php guestbook, where the input is stored in a file. MySQL would just be overkill, and light sql isn't installed (not my server). So I'm going with a basic file database. Anyways the problem I'm having is that the input provided by the textarea contains (may) returns, which cause havok upon the file database. I need a way to clean the input from everything, but text and spaces.
I've tried
But still with out much luck.
Here's a chunck of code...
Code: Select all
3/20/05 1
John Doe 2
Message of some sort goes here 3
more of the message here
and some more message.[/EDIT]
This has been bothering me a lot. I'm building a simple php guestbook, where the input is stored in a file. MySQL would just be overkill, and light sql isn't installed (not my server). So I'm going with a basic file database. Anyways the problem I'm having is that the input provided by the textarea contains (may) returns, which cause havok upon the file database. I need a way to clean the input from everything, but text and spaces.
I've tried
Code: Select all
$CommentClean = preg_replace('&[^a-z\d\s.]+&i', '', $Comment);
and...
$CommentClean2 = strip_tags($text);Here's a chunck of code...
Code: Select all
//Get the information supplied from the URL. (used if there are more than 10 entries)
//guestbook.php?page=2
$page=$_GET['page'];
$gbdatabase = 'gbdatabase.dat';
/*
// Provides: <body text='black'>
$bodytag = str_replace("%body%", "black", "<body text='%body%'>");
*/
//Open the database file (creates it if it does not exist) with read/write access
$file = fopen($gbdatabase, 'a+');
if(($Name!="") && ($Email!="") && ($Comment!=""))
{
//First lets get the date
$rawdate = getdate();
//$date is an array, we'll want to pull out the [hour, min] and [month, day, year]
$date = $date = $rawdate[hours] . ":" . $rawdate[minutes] . " " . $rawdate[mon] . "/" . $rawdate[mday] . "/" . $rawdate[year];
//$CommentClean = preg_replace('&[^a-z\d\s\r.]+&i', '', $Comment);
//$CommentClean2 = strip_tags($text);
$Comment = trim($Comment);
//Write lines to file (Name / Email, etc stored ontop of each other
fwrite($file, $date . "\n");
fwrite($file, $Name . "\n");
fwrite($file, $Email . "\n");
fwrite($file, $Comment . "\n");
fwrite($file, "EndEntry" . "\n"); //just a stop point
//Close file
fclose($file);
//clear variables
$Name = "";
$Email = "";
$Comment = "";
$date = "";
}