Takamine334 Posted June 19, 2008 Share Posted June 19, 2008 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> Quote Link to comment Share on other sites More sharing options...
trq Posted June 19, 2008 Share Posted June 19, 2008 <?php echo htmlentities('</title><body>'); ?> Quote Link to comment Share on other sites More sharing options...
Takamine334 Posted June 20, 2008 Author Share Posted June 20, 2008 Thank you for your help! Quote Link to comment Share on other sites More sharing options...
Takamine334 Posted June 21, 2008 Author Share Posted June 21, 2008 quick question. How would I do a newline for each htmlentities? I keep getting errors when I put in \n Quote Link to comment Share on other sites More sharing options...
trampolinejoe Posted June 22, 2008 Share Posted June 22, 2008 Depends what you mean? I think you should just be able to echo a <br> and that'll make a new line. show us some code Quote Link to comment Share on other sites More sharing options...
atl_andy Posted June 22, 2008 Share Posted June 22, 2008 check into <pre> tags. they should do what you need. Quote Link to comment Share on other sites More sharing options...
Stooney Posted June 22, 2008 Share Posted June 22, 2008 atl_andy was trying to say look into <pre></pre> tags. Quote Link to comment Share on other sites More sharing options...
chuckman Posted June 22, 2008 Share Posted June 22, 2008 when I write html code into my php code I don't use htmlentities.. you can do this echo("</title> \n <body>"); Quote Link to comment Share on other sites More sharing options...
HoTDaWg Posted June 22, 2008 Share Posted June 22, 2008 refer to the PHP manual. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted June 22, 2008 Share Posted June 22, 2008 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(). Quote Link to comment Share on other sites More sharing options...
Rezert Posted June 22, 2008 Share Posted June 22, 2008 <?php echo "<pre>"; echo htmlentities("</title> <body>"); echo "</pre>"; ?> Quote Link to comment Share on other sites More sharing options...
atl_andy Posted June 26, 2008 Share Posted June 26, 2008 Oops...didn't post that correctly. Thanks chris. Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted June 26, 2008 Share Posted June 26, 2008 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. Quote Link to comment 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.