Enters worden niet overgenomen bij plaatsen tekst

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Dirk

Dirk

07/09/2007 12:52:00
Quote Anchor link
Hallo,
Ik gebruik het volgende om tekst toe te voegen en te laten zien:

Post.php
----------

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?
$newsfile
= "news.txt";
//Open news.txt in read mode.
$file = fopen($newsfile, "r");
//b=begin  e=end
$btable = "<table class='sn'> <tbody>";
$bpost = "<tr><td class='sn-post'>";
$epost = "</td></tr>";
$etable = "</tbody></table><div><br /></div>";
//Define PHP Date format.  Used for the default date form value.
$defdate=date("d-m-Y");
//Other notes
if ($_SERVER['REQUEST_METHOD'] != 'POST'){
//If able to open file do...
if ($file) {
?>

<html>
<head>
<style type="text/css">
.mijnTekstVeld {
font-family:Arial;
background-color:"#e7cea5";
width:580px;
height:250px;
font-size:11pt;
border-style:solid;
border-width:1;
border-color:black;
color:#000000;
}
.mijnKnop {
background-color:"#e7cea5";
height:24px;
border-style:solid;
border-width:1;
border-color:black;
font-size:11pt;
font-weight:normal;
color:#000000;
}
</style>
</head>
<body>
<form action="
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
<? echo $_SERVER['PHP_SELF']; ?>
" method="post">
<div style="text-align: center">
Uw tekst<br /> <textarea rows="30" class=mijnTekstVeld cols="80" name="post"></textarea>
<br /><br />
<input type="submit" class=mijnKnop value="Tekst toevoegen" />
</div>
</form>
</body>
</html>
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?
}
else
//If can not open file complain...
echo "<html><head></head><body><p>Kon file niet openen. <br /> Permissies??</p></body></html>";
}


//ELSE IF browser sends a POST request. Make sure that data was actually
//entered into the form and then write that data to the file....

elseif ((isset($_REQUEST["post"])) && ($_REQUEST["post"]!="")) {

//Now we reopen the file in write mode.  This FIRST blanks the file.
$file = fopen($newsfile, "w");

//Write all of the table variables and the text entered into the form, plus the
//text that was already in news.txt to news.txt. The \n is a new line and it
//simply make news.txt more beautiful.  If it works display success message, if
//not display failure message.
// Fix quotes (') in entries and change any weird
//characters (&,<,>,etc) to their html equivalents.

$_REQUEST["post"] = stripslashes(($_REQUEST["post"]));
if(fwrite($file,$btable . " " . $bpost . " " . $_REQUEST["post"] . " " . $epost . " " . $etable . "\n " . $current_data))
echo "<html><head></head><body><p>Tekst is toegevoegd.<br /> <a href=\"\">Terug</a></p></body></html>";
else
echo "<html></head><body><p>Geen tekst toegevoegd.<br /> Permissies??</p></body></html>";

//Close the file.
fclose($file);
}


//If the browser sent a POST request but the user failed to put data in the form...spit out this error.
else
echo "<html><head></head><body><p>Geen tekst ingevuld. <br /> Probeer opnieuw.</p></body></html>";
?>


Display.php
-------------

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?
//This file displays the news by reading it from the news.txt file.  Make sure
//news.txt is chmoded 766.  The CSS definitions determine how the news will
//look.  To hardcode variables look into the "table vars" in post.php.
//You don't have to use this file to display news on your page.  Simply copy
//the CSS definitions to your CSS file and use the <? include... line in your
//PHP file wherever you want the news to be displayed.

?>

<html>
<head>
<style type="text/css">

table.sn {border-width: thin thin thin thin;
             border-spacing: 2px;
             border-color: gray gray gray gray;
             border-style: solid solid solid solid;
             border-collapse: collapse;
             text-align: center;
             empty-cells: show;
             background-color: white;
             margin-left: auto;
             margin-right: auto;
             width: 300px}

td.sn-title {font-family: sans-serif;
              border-width: thin thin thin thin;
              padding: 1px 1px 1px 1px;
              border-style: solid solid solid solid;
              border-color: gray gray gray gray;
              background-color: gray;
              color: black;
              font-size:14px;
              font-weight: bold}
td.sn-date {font-style: italic;
             font-family: sans-serif;
             border-width: thin thin thin thin;
             padding: 1px 1px 1px 1px;
             border-style: solid solid solid solid;
             border-color: gray gray gray gray;
             background-color: white;
             color: black;
             font-size:11px}
td.sn-post {font-family: monospace;
              border-width: thin thin thin thin;
              padding: 1px 1px 1px 1px;
              border-style: solid solid solid solid;
              border-color: gray gray gray gray;
              background-color: white;
              font-weight: bold;
              color: black;
              font-size:11px;}
</style>
</head>
<body>
<?
include("news.txt");
?>

</body>
</html>

En een file news.txt waar de tekst inkomt.

Alleen worden de enters niet overgenomen en wordt de tekst op 1 regel (achter elkaar) getoont.

Iemand een idee hoe/waar dit op te lossen?

Dirk.
 
PHP hulp

PHP hulp

06/05/2024 07:39:56
 
Kalle P

Kalle P

07/09/2007 13:03:00
 
Dirk

Dirk

07/09/2007 13:40:00
Quote Anchor link
Dank voor de snelle reaktie maar waar/hoe te wijzigen?

Moet ik

if(fwrite($file,$btable . " " . $bpost . " " . $_REQUEST["post"] . " " . $epost . " " . $etable . "\n " . $current_data))

wijzigen in

if(fwrite($file,$btable . " " . $bpost . " " . $_REQUEST["post"] . " " . $epost . " " . $etable . "\br " . $current_data))

Dirk.
 
GaMer B

GaMer B

07/09/2007 13:51:00
Quote Anchor link
nl2br() toepassen bij het ophalen van de data.
 
Robert Deiman

Robert Deiman

07/09/2007 13:54:00
Quote Anchor link
Nee, met fwrite laat je het zo staan, alleen met inlezen van de data haal je daar nl2br() over :)
 
Dirk

Dirk

07/09/2007 14:00:00
Quote Anchor link
Begrijp wat jullie bedoelen maar.... ehh, ik weet niets van PHP.
Heb dus geen idee waar dit aan te passen cq te wijzigen.

Dirk.
 
Dutch Caffeine

Dutch Caffeine

07/09/2007 14:04:00
Quote Anchor link
De enters, haal je er simpel uit, zoals al drie keer is gezecht:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
<?
nl2br($berict);

//De enters zijn er uit gehaald :)
?>


mr. de Jong
 
Dirk

Dirk

07/09/2007 18:25:00
Quote Anchor link
Ben nu de hele middag bezig maar krijg het (nog) niet voor elkaar.
Kan iemand mij even in de juiste richting duwen?
 
Henk

Henk

07/09/2007 21:05:00
Quote Anchor link
$_REQUEST["post"] = nl2br(stripslashes(($_REQUEST["post"])));
 
Dirk

Dirk

07/09/2007 21:49:00
Quote Anchor link
Henk,

Dank het is gelukt!

Nog 1 vraagje: waarom staat de tekst in het midden van het veld en begint dit niet links bovenaan? (in het display scherm).
Gewijzigd op 01/01/1970 01:00:00 door Dirk
 
Dirk

Dirk

08/09/2007 02:31:00
Quote Anchor link
Na een dagje stoeien is alles gelukt.

Dank voor jullie hulp.

Dirk.
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.