I'm trying to build a rudimentary (simple) content management system in PHP.
I have a input from with textfiled, and when submit is pressed, the content of the text filed writes itself into a 'text.htm'. It replaces the previous content.
here's the essential code:
Code: Select all
<?
phpfunction get_htmlspecialchars($given, $quote_style = ENT_QUOTES) {
return htmlspecialchars(html_entity_decode($given, $quote_style), $quote_style);
}
if (isset ($_POST['submit'])) {
if (!empty ($_POST['message'])) {
if ($fp = fopen ("text.htm", 'w')) {
if (ini_get ('magic_quotes_gpc')) {
$data = stripslashes ($_POST['message']);
} else {
$data = $_POST['message'];
}
get_htmlspecialchars($data);
fwrite ($fp, nl2br("$data"));
fclose ($fp);
header ('location: index.php');
}
}
}
?>I tried to replace:
fwrite ($fp, nl2br("$data"));
with:
fwrite ($fp, ("$data"));
thinking that this "nl2br" is responsable for adding an additional line break each time, but without it, all my other line breaks in "text.htm" desappear.
What should I do?