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

<?php


$act = $_POST['act'];
if($act == "post") {
    $name = $_POST 
['name'];
    $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!";
        exit;
    } else {
        //The file was successfully opened, lets write the comment to it.
              date_default_timezone_set('Europe/London');
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
        fclose($fp);

        //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">

    <table>

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

            <td>

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


</td>

        </tr>
    </table>
    <input type="hidden" name="act" value="post"></input>
    <input type="submit" name="submit" value="submit"></input>
</form>
</p>
</div>



<?php
}
?>
</div>

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

This
is 
a
test
comment!

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?

sanchixx

Recommended Answers

All 4 Replies

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

You have solved your problem, I am assuming?

no

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 for diafol

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, networking, learning, and sharing knowledge.