cgm225 Posted August 16, 2008 Share Posted August 16, 2008 I have a notes/blog app I coded in which (1) I grab an entry from a database, then (2) use the nl2br() function on the body of the entry, followed by (3) outputting of the that text (now with html BR tags). However, as seen here for example (see the html source code), using the nl2br() function messes up my nice HTML source code organization (i.e. the uniform indenting of the code, etc). Therefore, I wanted to know if there was another way to insert html BR tags for carriage returns within the body of my note entries when outputting them so that there will not also be inserted a break in the html source code (i.e. essentially a \n after the break, which I don't want). Basically, I want my source code to look pretty again, and nl2br is messing it all up... Any ideas? Looking for a simple solution here. Thanks again! note, by BR tags I mean <br /> Link to comment https://forums.phpfreaks.com/topic/119939-looking-for-simple-solution-to-styling-html-source-code/ Share on other sites More sharing options...
marcus Posted August 16, 2008 Share Posted August 16, 2008 <?php $string = "this string has breaks in it"; echo str_replace("\n","<br>",$string); ?> that will just replace a new line with a break and not a break and an additional return. Link to comment https://forums.phpfreaks.com/topic/119939-looking-for-simple-solution-to-styling-html-source-code/#findComment-617861 Share on other sites More sharing options...
cgm225 Posted August 16, 2008 Author Share Posted August 16, 2008 Thank you so much! Link to comment https://forums.phpfreaks.com/topic/119939-looking-for-simple-solution-to-styling-html-source-code/#findComment-617864 Share on other sites More sharing options...
teng84 Posted August 16, 2008 Share Posted August 16, 2008 <a href="http://www.php.net/manual/en/function.nl2br.php">nl2br</a> Link to comment https://forums.phpfreaks.com/topic/119939-looking-for-simple-solution-to-styling-html-source-code/#findComment-617876 Share on other sites More sharing options...
marcus Posted August 16, 2008 Share Posted August 16, 2008 <a href="http://www.php.net/manual/en/function.nl2br.php">nl2br</a> ^^didn't bother reading first post. Link to comment https://forums.phpfreaks.com/topic/119939-looking-for-simple-solution-to-styling-html-source-code/#findComment-617880 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.