Jump to content

How can I echo HTML?


Takamine334

Recommended Posts

Hi - I'm brand new to PHP. I'm trying to figure out how to echo some HTML. The problem is, I need it to echo as though it were text, not actual HTML to be used. For example, how would I echo </title><body> so that when I viewed the PHP page online, it would show:

 

</title><body>

Link to comment
Share on other sites

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
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
Share on other sites

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.