PHP Code:
<?
if($HTTP_POST_VARS['submit']) {
if($HTTP_POST_VARS['password'] == 'pass') {
if(!$HTTP_POST_VARS['name']) {
echo "You must enter a name";
exit;
}
if(!$HTTP_POST_VARS['news']) {
echo "You must enter some news";
exit;
}
if(strstr($HTTP_POST_VARS['name'],"|")) {
echo "Name cannot contain the pipe symbol - |";
exit;
}
if(strstr($HTTP_POST_VARS['news'],"|")) {
echo "News cannot contain the pipe symbol - |";
exit;
}
$fp = fopen('includes/news.txt','a');
if(!$fp) {
echo "Error opening file!";
exit;
}
$line = date("j F Y - h:i A") . "|" . $HTTP_POST_VARS['name'] . "|" . $HTTP_POST_VARS['news'] . "|" . $HTTP_POST_VARS['title'];
$line = str_replace("\r\n","<BR>",$line);
$line .= "\r\n";
fwrite($fp, $line);
if(!fclose($fp)) {
echo "Error closing file!";
exit;
}
} else {
echo "Bad Password";
}
}
?>
This is a simple script that i went through for someones website so they can submit news without the use of a database. It all works fine apart from the fact that everytime a comma occurs a backslash is added. I believe this is down to the str_replace function and as soon as i saw it i wanted to replace it with nl2br() but the problem is, when i do replace it with the nl2br() function is screws up the layout of the news completely.
Any ideas?