I’m using the following code to post the content of a text box to an HTML file. When the info is submitted, I want there to be <br/> inserted where line-breaks are. I thought using this code would fix the problem:
$content = nl2br($_POST['content']);
But it seems to produce the following if there is already a <br /> in place:
Lorum ipsum.
<br /><br />
How do I remedy this?
The post code:
<?php
$fn = "people.html";
if (isset($_POST['content']))
{
$content = stripslashes('content');
$content = nl2br($_POST['content']);
$fp = fopen($fn,"w") or die ("Error opening file in write mode!");
fputs($fp,$content);
fclose($fp) or die ("Error closing file!");
}
?>
How it’s being submitted:
<form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="post">
<textarea rows="25" cols="40" name="content"><?php readfile($fn); ?></textarea>
<input type="submit" value="Sauver">
</form>
Something like that should strip excess whitespace around line breaks for you.
Also, why are you using stripslashes? That should only be necessary if you have magic quotes on, and you shouldn’t have magic quotes on. You also have got that line’s syntax wrong anyway.
edit: Still trying to interpret what you’re saying. I’m thinking this might help:
Will start with the correct data. Perhaps.