I have a comment box that uses php her is the code:


$act = $_POST['act'];
if($act == "post") {
    $name = $_POST 
    $area  = $_POST ['area'];
    @$fp = fopen("comments.html", 'a');
    if (!$fp) {
        //The file could not be opened
        echo "There was an error! Please try again later!";
    } else {
        //The file was successfully opened, lets write the comment to it.
setlocale (LC_ALL, "en_GB"); 

              $outputstring = "<p class=three><b>" .$name. " </b> on ".strftime('%A %e %B %Y ')." at ".strftime('%H:%M')." GMT wrote:</br></br> " .$area. "</p>" ;

        //Write to the file
        fwrite($fp, $outputstring, strlen($outputstring));

        //We are finished writing, close the file for security / memory management purposes

        //Post the success message
        header('Location: article1.php');   
} else {
    //We are not trying to post a comment, show the form.
<p class=three>Comments:</p>
<?php include("comments.html"); ?>

<div id="shadow">
Send a comment:
<form action="article1.php" method="post">


            <td><input type="text"  name="name" style="font-family:arial; font-size = 12pt" size="60" value="anonymous"></input></td>


<textarea name="area"  style="font-family:arial; font-size = 12pt" rows = "8" cols = "48" wrap="hard">\n\n</textarea><br>


    <input type="hidden" name="act" value="post"></input>
    <input type="submit" name="submit" value="submit"></input>


When i submit my text that i showed like this in the textarea:


I get this:

This is a test comment!

I can solve this by putting the </br> tag but people that d'ont know html cant how can i put a </br> automaticly?


Recommended Answers

All 4 Replies

By the way, the right tag for a break is <br />

You have solved your problem, I am assuming?


i would like that when After each 48 charters in the in the textarea It must insert an auto <br> inside of it. And it must continue until it's done with all the charters.

Member Avatar

nl2br() is a standard convert newlines to break tag in php.
If you want this to happen every 48 characters, even inside words, you can split with str_split or a variety of other string splitting functions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.