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 = "";
}