Jump to content

How can I echo HTML?


Takamine334

Recommended Posts

  Quote

quick question. How would I do a newline for each htmlentities? I keep getting errors when I put in \n

 

A \n would be a newline character (on certain OS's). However, a browser does not display the newline character; you'll need the <br /> tag for that. Obviously this does not want to be converted with htmlentities().

Link to comment
https://forums.phpfreaks.com/topic/110842-how-can-i-echo-html/#findComment-571413
Share on other sites

The problem with telling him to just use htmlentities is that he probably doesn't know why it works.

 

 

Takamine, html tags display as they are supposed to when "<anything>" is types. Anytime html sees a "<" it won't print anything out until after a closing ">" is printed, and then it makes whatever changes are needed til is sees a closing "</whatever>" tag. So for you to print a < without it thinking it's an html tag, you'll need to type out the assosicated 'entity' code for it.

 

For example, ya know how if you type 5 space between words, it doesnt care and only adds one space? Well, the space entity code is ' ' so if you want 5 spaces, you need to type 5  's or else it won't print them. Now, the easy way to add entities is as suggested, with the htmlentities function. But if you dont' want to have to to that all the time, you can do the entity code for the < and > which is < and >, respectively. An easy way to remember is all entities starts with a & and end with a ;. And with these 2, you have a 'greater than' sign and a 'less than' sign. Hence, < and > There is an entity for (I think ) every character that needs to be displayed literally on the page.

 

Hope that made sense.

 

Hope that made sense.

Link to comment
https://forums.phpfreaks.com/topic/110842-how-can-i-echo-html/#findComment-574661
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.