Jump to content

Big problems with linebreaks


indigo diingo

Recommended Posts

Hi

 

I know the code is long but you can see the result of the problem at http://www.rhythmbeats.be/band/agenda.php

 

The first problem:

If you insert two messages, and then a third, the first one gets deleted. If I delete the \n at the end of this code, it all works fine (and in the regex).

$nieuw = "<span id=\"$id\">" . '<p class="naam">' . $naam . '</p><p class="boodschap">' . $boodschap . '</p>' . '<p class="datum">' . $datum . " || <a href=\"agenda.php?actie=verwijderen&id=$id\">verwijderen</a></p><br /></span>\n";

 

The second problem:

If you add an enter in the textarea and add the message, it will be fine, but if you add a second message, the first part before the linebreak of the first will be gone. Very strange.

 

 

 

If anyone could help me with one of these problems I woul really appreciate it since I am out of ideas to solve this. Both problems are problems with linebreaks!

 

Thanks

 

Complete code:

<?php
$titel = 'agenda';

$header = '<link rel="stylesheet" type="text/css" href="agenda.css" />';

$tekstveld = '<form action="agenda.php" method="post">
<p><input name="naam" id="naam" type="text" maxlength="50"></input></p>
<p><textarea name="boodschap" id="boodschap"></textarea></p>
<input type="submit" value="Toevoegen" />
</form>';

$url = 'boodschappen.txt';

if((strlen($_POST['naam'])>=2) && (strlen($_POST['boodschap'])>=2)) {
$naam = $_POST['naam'];
$boodschap = nl2br($_POST['boodschap']);
$id = date('ymdHis');
$datum = date('__ H:i __ l F j __ o');

$nieuw = "<span id=\"$id\">" . '<p class="naam">' . $naam . '</p><p class="boodschap">' . $boodschap . '</p>' . '<p class="datum">' . $datum . " || <a href=\"agenda.php?actie=verwijderen&id=$id\">verwijderen</a></p><br /></span>\n";
}

if(file_exists($url)) {
$boodschappen = fopen($url,'r');
$origineel = fgets($boodschappen);
fclose($boodschappen);

unlink($url);

if($_GET['actie']=='verwijderen') {
	$id = $_GET['id'];

	$origineel = preg_replace ("/<span id=\"$id\">.*?<\/span>\n/",'',$origineel);
	$nieuw = '';
}

$boodschappen = fopen($url,'w');
$tekst = $nieuw . $origineel;
fwrite($boodschappen,$tekst);
fclose($boodschappen);
}
$inhoud = $tekst  . $tekstveld;


$bestand = 'agenda.html';
if(is_file($bestand)){
$template = file_get_contents($bestand);
$template = str_replace('{titel}',$titel,$template);
$template = str_replace('{header}',$header,$template);
$template = str_replace('{inhoud}',$inhoud,$template);
echo $template;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/149168-big-problems-with-linebreaks/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.