Indeed. Actually, all you need has already been suggested by Fou-Lu, but since he knows everything ever I think that his examples might go over your head rather easily.
This code he posted on the previous page:
PHP Code:
printf('<p class="paragraph">%s</p>', implode('</p><p>', explode("\n", trim($paragraph))));
I suppose the best way to look at this is backwards, since that is more or less the way it will run.
- You pass
$paragraph into a trim function, to make sure there isn't hanging off whitespace.
- This is then exploded into an array, with the break being on newlines.
- It's then put back together with implode, however, this adds
</p><p> after each item as it does so.
- The result of all that will be put in the position of the
%s in the first part of the printf.
Making sense so far? That means if your database output this:
Quote:
|
This is a paragraph. \n This is another paragraph.
|
The above would reach the page as:
Code:
<p class="paragraph">This is a paragraph.</p><p>This is another paragraph.</p>
Edit: It would probably be more like this, actually (And I don't know if the newlines stay or not):
Code:
<p class="paragraph">This is a paragraph. </p><p> This is another paragraph.</p><p></p>
This would be used like so, in your code:
PHP Code:
<?php
// ... Other stuff
echo "<b>Name:</b> ". $name."<br/>"."<br/>" ;
echo "<b>Address:</b> ". $address."<br/>"."<br/>"."<br/>";
echo "<b>Paragraph(s) below:</b>"."<br/>";
?>
<div class="paragraph">
<?php
printf('<p class="paragraph">%s</p>', implode('</p><p>', explode("\n", trim($paragraph))));
?>
</div>
For formatting that end result, you have two options as mentioned above by Fou-Lu. Assigning the class durring the implosion so all elements end up with your class, example (Note: implosion):
PHP Code:
printf('<p class="paragraph">%s</p>', implode('</p><p class="paragraph">', explode("\n", trim($paragraph))));
Or using "inheritance" (or more correctly, a descendant selector) in the CSS:
Code:
p.paragraph p { /* style for p tags inside p tags with class paragraph */ }
Hope this helps you understand it all a bit.

(Hope I explained it all right

).