I know about nl2br, but is there a way to convert the text into formatted paragraphs?
Converting textarea text to formatted paragraphs
textarea by default supports HTML, therefore you could put in tags inside the textarea and the text will be formatted...
What you could do is to format the text afterward after you submitted your textarea vars via POST or GET.
$formattedText = "<p>". $_POST["textAreaStuff"] . "</p>";
And using css, you could format it nicely.
<style>
p {
background-color: #999999;
color: #000000;
font-family: Verdana;
font-size: x-small;
}
</style>
However if you want to format the textarea realtime, then you should use CSS and format the textarea element.
<style>
textarea {
background-color: #999999;
color: #000000;
font-family: Verdana;
font-size: x-small;
}
</style>
Preferably assign a class to avoid confusion.
<textarea class="nicer">inside text</textarea>
<style>
textarea .nicer{
background-color: #999999;
color: #000000;
font-family: Verdana;
font-size: x-small;
}
</style>
Whatever suits you best.
Good luck!
Well if the text in the textarea was for example:
Text
Text
Text
If I used nl2br it would end up like this:
Text<br />
<br />
Text<br />
<br />
Text<br />
<br />
Is there a way in which I can make it end up like this?:
<p>Text</p>
<p>Text</p>
<p>Text</p>
If you really have to end up like this, you could do :
$yourText = "Text<br /><br />";
$yourText = str_replace("<br />", "", $yourText);
$newText = "<p>" . $yourText . "</p>";
Wouldn't that end up being:
<p>Text Text Text</p>
As you notice, i declared this line:
$yourText = "Text<br /><br />";
So I wasn't spefically pointing at your situation.
Ok, if you want to do it exactly like this:
Text<br />
<br />
Text<br />
<br />
Text<br />
<br />
Then do this:
$strBrPieces = explode ("<br /><br />", $yourText);
foreach ($strBrPieces as $value) {
$newText .= "<p>". $value . "</p>";
}
echo $newText;
For some reason, it still ended up:
<p>Test
Test
Test</p>
I don't know but it works for me.
I put up a little demo just to be sure.
http://www.sugoidesign.com/sample.php
here's the complete code i tested this with:
<?php
$yourText="
Text<br /><br />
Text<br /><br />
Text<br /><br />";
$strBrPieces = explode ("<br /><br />", $yourText);
foreach ($strBrPieces as $value) {
if (!empty($value))
$newText .= "<p>". $value . "</p>";
}
echo $newText;
?>
EDIT: I added a !empty to avoid a last repeat of <p></p> on the last element of the array.
Hope this works
I made an error before, but it works now. Thanks a lot dcav