Enters worden niet overgenomen bij plaatsen tekst
Ik gebruik het volgende om tekst toe te voegen en te laten zien:
Post.php
----------
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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) {
?>
$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="" 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)
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
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>";
?>
}
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)
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
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.
//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.
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.
nl2br() toepassen bij het ophalen van de data.
nl2br() over :)
Nee, met fwrite laat je het zo staan, alleen met inlezen van de data haal je daar Heb dus geen idee waar dit aan te passen cq te wijzigen.
Dirk.
Kan iemand mij even in de juiste richting duwen?
$_REQUEST["post"] = nl2br(stripslashes(($_REQUEST["post"])));
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
Dank voor jullie hulp.
Dirk.