Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/98497-problem-displaying-phphtml-code/
Share on other sites

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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.