flunn Posted March 29, 2008 Share Posted March 29, 2008 Greetings: I'm trying to use htmlentities() to display html/php code on a web page. It works fine except for one problem: the code is displayed as a single line, but I want line breaks where I have put them in my editor. Any advice as to how to solve this problem would be much appreciated. regards to all from flunn Quote Link to comment https://forums.phpfreaks.com/topic/98497-problem-displaying-phphtml-code/ Share on other sites More sharing options...
Steve Angelis Posted March 29, 2008 Share Posted March 29, 2008 Have you tried adding in this? echo "<br>"; somewhere? Quote Link to comment https://forums.phpfreaks.com/topic/98497-problem-displaying-phphtml-code/#findComment-504065 Share on other sites More sharing options...
PFMaBiSmAd Posted March 29, 2008 Share Posted March 29, 2008 New lines \n or \r\n are not html. To get them to result in html newlines, either wrap the code you want to display in < pre > .... < /pre > tags (without the spaces inside the tags) or use the php nl2br() function to insert html newlines. Quote Link to comment https://forums.phpfreaks.com/topic/98497-problem-displaying-phphtml-code/#findComment-504076 Share on other sites More sharing options...
flunn Posted March 30, 2008 Author Share Posted March 30, 2008 Thanks to Steve Angelis and PFMaBiSmAd for their replies. I've tried the "<pre>" and the nl2br() ideas, but without success I'm afraid. I've also tried a couple of online translators that are supposed to make code friendly for display. They solve part of the problem but if I put in all the code I want to display they generate php errors like ("expecting T_string") I'm afraid I've got in over my head here. Anyway thanks again to both of you and regards to all from flunn Quote Link to comment https://forums.phpfreaks.com/topic/98497-problem-displaying-phphtml-code/#findComment-504813 Share on other sites More sharing options...
redarrow Posted March 30, 2008 Share Posted March 30, 2008 You use <br><br> or <p></p> but from the database when the data was submitted use nl2br() function but you do not use the nl2br() function to insert data only to output data....... Quote Link to comment https://forums.phpfreaks.com/topic/98497-problem-displaying-phphtml-code/#findComment-504817 Share on other sites More sharing options...
sasa Posted March 30, 2008 Share Posted March 30, 2008 use html <pre> tag Quote Link to comment https://forums.phpfreaks.com/topic/98497-problem-displaying-phphtml-code/#findComment-504874 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.