loquela Posted March 12, 2008 Share Posted March 12, 2008 I'm trying to pull text from a database and disply it in HTML. The text in the database contains no html tags so when it is displayed as HTML it is displayed as a continuous string: Database source text: This is the firstparagraph of the text. This is the second paragraph. Etc.... Text as dislayed in HTML: This is the first paragraph of the text. This is the second paragraph. Etc.... What I really want to do is create praragraph blocks in the HTML: This is the firstparagraph of the text. This is the second paragraph. Etc.... To <p>This is the firstparagraph of the text.</p> <p>This is the second paragraph.</p> <p>Etc....</p> Or at the very least replace the ascii line breaks with <br /> . How is this achieved? Link to comment https://forums.phpfreaks.com/topic/95799-ascii-text-to-html-help-please/ Share on other sites More sharing options...
Barand Posted March 12, 2008 Share Posted March 12, 2008 echo nl2br($dbtext); Link to comment https://forums.phpfreaks.com/topic/95799-ascii-text-to-html-help-please/#findComment-490437 Share on other sites More sharing options...
loquela Posted March 12, 2008 Author Share Posted March 12, 2008 That was painless . Sorted. Many thanks Link to comment https://forums.phpfreaks.com/topic/95799-ascii-text-to-html-help-please/#findComment-490459 Share on other sites More sharing options...
loquela Posted March 17, 2008 Author Share Posted March 17, 2008 Many thanks so far. Could we now go a step further? Instead of having a long string of text with just <br> How would it be possible to format the ascii text more semantically: ASCII: Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean est. Maecenas varius scelerisque ligula. Morbi est nibh, bibendum pulvinar, interdum ac, fringilla non, lacus. In hac habitasse platea dictumst. to HTML: <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p> <p>Aenean est. Maecenas varius scelerisque ligula. Morbi est nibh, bibendum pulvinar, interdum ac, fringilla non, lacus.</p> <p>In hac habitasse platea dictumst.</p> Many thanks in advance. Link to comment https://forums.phpfreaks.com/topic/95799-ascii-text-to-html-help-please/#findComment-493914 Share on other sites More sharing options...
Barand Posted March 17, 2008 Share Posted March 17, 2008 replace your linefeeds with "</p><p>" and place the whole text inside <p> ... text ... </p> Link to comment https://forums.phpfreaks.com/topic/95799-ascii-text-to-html-help-please/#findComment-494206 Share on other sites More sharing options...
loquela Posted March 26, 2008 Author Share Posted March 26, 2008 Many thanks Barand, very helpful Link to comment https://forums.phpfreaks.com/topic/95799-ascii-text-to-html-help-please/#findComment-501303 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.