cgm225 Posted June 22, 2008 Share Posted June 22, 2008 I have a string of text in a variable, let's say: $text = "<a href='example.com'>Example.com</a>\n<a href='test.com'>Test.com</a>"; ...and I echo the string with nl2br... echo nl2br($text); ...which returns in my html source code as: <a href='example.com'>Example.com</a><br /> <a href='test.com'>Test.com</a> This is fine, but I am having the following problem when I use it as follows... <html> ...snip... <a href='somelink.com'>somelink.com</a><br /> <?php echo nl2br($text); ?> <a href='somelink.com'>Example.com</a><br /> ...snip... </html> ...because the nice indentation of the html source code is not preserved, and looks something like... <html> ...snip... <a href='somelink.com'>somelink.com</a><br /> <a href='example.com'>Example.com</a><br /> <a href='test.com'>Test.com</a> <a href='somelink.com'>Example.com</a><br /> ...snip... </html> Here is my question... how do I get every new line created with the nl2br function to also get an indentation in the html source code? Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/111403-indent-problems-with-styling-of-html-source-code-while-using-nl2br-function/ Share on other sites More sharing options...
trq Posted June 22, 2008 Share Posted June 22, 2008 tidy. Link to comment https://forums.phpfreaks.com/topic/111403-indent-problems-with-styling-of-html-source-code-while-using-nl2br-function/#findComment-571833 Share on other sites More sharing options...
cgm225 Posted July 12, 2008 Author Share Posted July 12, 2008 Ok, so I have tidy installed now... how would I use it to accomplish what I outlined above? Link to comment https://forums.phpfreaks.com/topic/111403-indent-problems-with-styling-of-html-source-code-while-using-nl2br-function/#findComment-588434 Share on other sites More sharing options...
wildteen88 Posted July 12, 2008 Share Posted July 12, 2008 Have a look at the documentation for how to use the tidy library, You might want to look into the tidy_parse_string function here. Link to comment https://forums.phpfreaks.com/topic/111403-indent-problems-with-styling-of-html-source-code-while-using-nl2br-function/#findComment-588453 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.